Send email with PDF attachment in NAV 2009

In this post I would like to explore the possibilities to create an email from the Role Tailored client and attach an invoice as a PDF file to the email, unfortunately we have do not have this functional build into our Demo application, but let me show you how this can be do with little effort.

When downloaded the fob file you will see that I have added 5 new actions

image

1. SendAsPDF(Use of codeunit to rename) recommended solution
2. SendAsPDF(Access to Server needed)
3. SendAsPDF(With Temp file name)
4. SendAsPDF(User prompted to save)
5. SaveAsPDFrecommended solution(if you just want the PDF file)

Let me go through the different options starting from the bottom, since I recommend option 1, but I would also like to share other options for doing this, since these might be valuable for you.

Option 5: SaveAsPDF
In this option you will get prompted if you want to open or save the PDF. The PDF file created will be based on the select Invoice in the Posted Sales Invoices List Place

image

In this option all I do is to have the server create the PDF file for me and use the new download function in NAV 2009 to retrieve the PDF file created on the server.

Option 4: SendAsPDF(User prompted to save)
In this option, you will first be prompted to save the file.
Here it is important to select to “”SAVE” the PDF file on the disk, to have the correct name of the PDF file. If you select to “OPEN” the PDF filename will be given a temp name.

After you have saved the PDF we now create the email message you will get 3 messages similar to this when this happens:

image

You get these message because we connect to an external component(Outlook) to the Role Tailored client. It is of course up to you if you want to set this to “Always allow”, but this would remove these messages, the next time you open the Role Tailored client.

When you have allowed these to run, email will be created with the PDF file attached.

image

In this option all I do is to download the PDF to the client and then use the Mail codeunit to create the email

Option 3: SendAsPDF(With Temp file name)
In this option, you will not be prompted to save the PDF file.
And the email will be created immediately. This would probably be the preferred compared to downloading this to the user disk, but we will use the PDF file created on the server, and since this file get a TEMP name, like this: “__TEMP__570eb0279b9d4b1fa837caf3a14acbf7” this option is not really good.

Let us look at the option 1 and 2 where this issue is solved.

Option 2: SendAsPDF(Access to Server needed)
In this option you will not be prompted to save the file either, but here the end user will need to have access the server folder where the PDF is stored on the server. In some situation you might want this, but for security reasons you might also not want to give this access to the user.

Option 1: SendAsPDF(Use of codeunit to rename) recommended solution
Again in this option you will not be prompted to save the PDF file, but the PDF file will be automatically added to the email. In this option we have build a codeunit to rename the TEMP file created on the server, and end user will not need to have access to any folders on the server.