Mail Sending Option in NAV 2017 with Cover Letter & Attachments –Part 2

Continuing from previous post, further in next step we will apply same feature discussed in earlier post to our custom documents and learn where all places we need to take care development to get it working.

If you have missed First Part you can find here. Mail Sending Option in NAV 2017 with Cover Letter & Attachments –Part 1

In my Example I am using Policy Module:

I am using my Custom Table Policy where Policy Holder is setup as Customer, also few general details related to policy is stored. In nutshell we are concentration on Sending mail to customer as we have done in previous post for sending Invoice details to customer.


In my Policy Table I have added 2 Function as below:





IF DocumentSendingProfile.LookupProfile(“Policy Holder No.”,FALSE) THEN



SendProfile(VAR DocumentSendingProfile : Record “Document Sending Profile”)


DummyReportSelections.Usage::”Policy Issue”,Rec,”Document No.”,”Policy Holder No.”,

DocTxt,FIELDNO(“Policy Holder No.”),FIELDNO(“Document No.”));


In Table 77 Report Selections add new option to usage field



In Table 60 Document Sending Profile add below customization.

Add Text Constants


Update below function as:



In Table 9657 Custom Report Selection add below customizations.





In Page 9657 Custom Report Selection add below customization.







Create 2 Reports one for Mail Body and one for Attachment. You can use same report as attachment too, it depends on your requirement.


In Page Policy add below customization.





Setup your report Selection as below:


Now you are good to go.

Test your solution/ customization.

This is just a small idea, many lots can be done depending upon your requirements.




Export Data as CSV and send as Attachment to Mail

One of my Follower/Reader have requested for this post.

This post will explain the the below steps:

  • Export the data of table to csv file format. (I am using XMLPort you can use Excell Buffer or any other method to create the file)
  • Attach to Mail and Send.

Step 1.

Create a XMLPort as below.


Set the Property of XMLPort.


Set the Property of Integer Data Item.


Set the Property of Table DataItem for which data to be exported.


Set the Captions of the Columns in CSV file.


Write the code to transfer the value of Table columns.

You may find some extra code adjust accordingly as per your requirement.


Define a function to Setfilter for data to export.

Adjust the code as per your requirement.



Step 2.

Here is the function to Export the data to csv File using above created XMLPort.

This function Saves the file to Shared folder, if required you can use TEMPORARYPATH to save your File.


Step 3.

Send the File as Attachment to the Mail.


You make required adjustment as per your requirement.

Make sure in case you are using Shared Folder give necessary rights on folder to Service Account and operating User Accounts.

Please respond did you found useful this information.

Their are other ways to achive the same, this was readyly available with me as i have used in one of my project so shared the same.

Stay tuned for more details in my Up comming posts.

Creating File Attachment to Mail for Report

We generally get requirements from clients to send report output as attachment to the mail.

In Microsoft Dynamics Navision 2015 this feature is available at most of the places, but we can design for other earlier versions too.

Long-time back I was having this requirement from one of my client, those days I scanned lots of website and tried lots of method. This one I found compact and easy to use. Their after whenever I get similar requirements I prefer using this.

Today I wish to share the same with others, as I have used it in my several implementations and found it working perfect and tested with several clients.

Let’s see this, it could help someone getting his work done in easy way and can save lots of time from hit and try with several methods.

First step, I will create a function which will help us generating the file on Service tier and down load to local temporary folder, so that we can easily access and attach to our mail.

Let’s give it a meaningful name like: DownloadToClientFileName

I will define two parameters for this Function as below:

Var Name DataType Subtype Length
No ServerFileName Text 250
No ToFile Text 250

I will define Return Value of Function as: Text of Length 250

I will define Local Variables for Function as below:

Name DataType Subtype Length
ClientFileName Text 250
objScript Automation ‘Microsoft Script Control 1.0’.ScriptControl
CR Text 1

Now we will write Code for the Function as below:

ClientFileName := ToFile;

IF NOT DOWNLOAD(ServerFileName, ”, ‘<TEMP>’,”, ClientFileName) THEN




CR := ‘ ‘; CR[1] := 13;

objScript.Language := ‘VBScript’;


‘function RenameTempFile(fromFile, toFile)’+CR+

‘set fso = createobject(“Scripting.FileSystemObject”)’+CR+

‘set x = createobject(“Scriptlet.TypeLib”)’+CR+

‘path = fso.getparentfoldername(fromFile)’+CR+

‘toPath = path+”\”+left(x.GUID,38)’+CR+

‘fso.CreateFolder toPath’+CR+

‘fso.MoveFile fromFile, toPath+”\”+toFile’+CR+

‘RenameTempFile = toPath’+CR+

‘end function’);

ClientFileName := objScript.Eval(‘RenameTempFile(“‘+ClientFileName+'”,”‘+ToFile+'”)’);

ClientFileName := ClientFileName+’\’+ToFile;



Second Step, I will write code to call this function to attach the file to Mail and send using SMTP as below:

//SMTP is an Variable of Codeunit SMTP Mail


//SenderName,SenderAddress,Recipent is an email addresses



//MailReport is Variable for Report of which output we want to use as attachment.

//Name & ToFile is Text type variable of Length 250

Name := STRSUBSTNO(‘Estimate No. %1.pdf’, SalesHeader.”No.”);

//Creating File Name

ToFile := Name;

FileName := TEMPORARYPATH + ToFile;

//We are using temporarypath OS Variable to get the path for file



ToFile := DownloadToClientFileName(FileName, ToFile);




Now you can create a template function and use where ever require.


Most of the contents you find in this blog will be either inherited from MSDN or Navision Developer IT Pro Help. Some places images are also directly taken from these sites. Purpose is simple to try those stuffs and re-produce adding few things as per my understanding to make easy understanding for others and quick reference.

Here nothing under my own brand or authorship of the content. At any point of time we are just promoting Microsoft stuffs nothing personnel with same.

Hope stuffs used here will not violate any copyright agreement with them. In case by mistake or in-intestinally it happens and the Microsoft feels these should not be used Microsoft have full right to inform me about same and will be glad to take down any such content which may be violating the norms.

Purpose is to promote Navision and share with community.

FB Profile

Like FB Page

%d bloggers like this: