Skip to main content

Microsoft Dynamics NAV 2017 - Email From NAV Part 1.

Hi Readers,

Today I would like to discuss a simple feature that Microsoft is working to be a part of standard NAV or I would say developed a Pattern for, but most of us are still using the old customizing ways which are hard as well as confusing to other developers.

The Pattern in Developed and Enhanced from Microsoft starting NAV 2015. In today's article we will discuss how to use the pattern if we want to send an email from NAV and the in the future article we will discuss other enhancements which can be used instead of customizing NAV.

The idea is Simple - Using base approach and Customize Less, Saves Cost to Customer and hassle for other developers.

Your comments are awaited for future articles.

** This pattern is available from NAV 2015 onwards but for demo, we will be using in NAV 2017.

A new Table and Codeunit have been introduced in NAV for email pattern.
Table       - 9500 - Email Item.
Codeunit - 9520 - Mail Managment.

It take care of most of the things, some of them are listed below -
  1. Raise a Dialog before sending an email. [Optional]
  2. Send Email via Job Queue. [No Errors are shown]
  3. Attach Document.
  4. Add CC & BCC Email ids.
  5. Append a Body in Email Using a Blob.
  6. Check Valid Email Address.
  7. Add Media. 
  8. Plain Text Formatted.
  9. Get Sender Address From - Current User ID, Office 365, SMTP Setup, User Setup, Authentication Email & Active Directory.
I think it might interest you, I am sure these are all the cases that we want to be supported as a customization.

The only feature that I would request to add in this pattern is a possibility to add multiple attachments in an E-mail Item.

Any email that you want to send with max. 1 attachment can be send using this pattern.

So let's see how to use this pattern in code.

Case - My Customer requested to customize NAV for the possibility of sending Report Open Customer Entries using an action on customer page.

Let's Create a Codeunit to send email using the Pattern discussed above -

1. Create a Function which accepts Customer record as a parameter. 

This function check that Email Exist on Customer or not and then generates the record in Email Item.


2. Create Two supported functions which be called from above function.
These functions create Email Body and Email Attachment.


3. Let's Now add action in Customer List / Card which calls this custom codeunit function. 


Now Let's Demo the code - 


If all setup is correct then the system will generate an email as shown below.


Hope it helps.

Let me know if it makes sense there are so many additional features in this pattern that I would like to explain if this article helps my readers.

Waiting for your reply.

You can download the codeunit from OneDrive.

File Name- Microsoft Dynamics NAV 2017  - #SauravNAV_Email_Pattern_V1.0

Let me know your views.

Regards,
Saurav Dhyani
saurav-nav.blogspot.in

Comments

  1. This was a terrific article and helped me immensely. You are such a wealth of information, Saurav.... I am very thankful for your efforts in the NAV community.

    ReplyDelete
    Replies
    1. Thanks Justin for kind words. Its great to hear that my content was helpful.

      Delete
  2. Hello,
    I have tried the same for Sales quote in NAV 2018 but getting some error and email not getting generated.
    Could you please suggest.

    ReplyDelete
  3. i have tried the same code for sales quote but it didn't work. Can you help?

    ReplyDelete
  4. I am trying this pattern in a report. It is working fine so far, however I do not understand how you managed to generate the body. What type of variable is 'EmailBody'?

    ReplyDelete
    Replies
    1. EmailBody is of type Record Variable for Table TemBLOB.
      You can also download objects from OneDrive Link at the end of article.

      Delete
    2. Thank you! I can not use the objects, since we have no development license for code units (that's why I use a report). It's working flawlessly so far. Thanks a lot for this blog!

      Delete
  5. There are new Fields in the Email-Item Table in Business Central. One of them is "Attachment File Path 2". Is it now possible to add more than one Attachment to an email using your way?

    Thanks in advance

    ReplyDelete
    Replies
    1. True.
      In Business central 2020 Wave 2, there are unlimited attachments that you can add.

      Delete

Post a Comment

Popular posts from this blog

BC 21 and Higher - PowerShell Cmdlet (Replacement of Business Central Administration).

Hi Readers, As discussed in last article about deprecating of Business Central Administration, there are few common actions that we use in administration till Business Central 20. For our on-prem customers, we will still require doing activities. As Microsoft suggest we need to start using PowerShell cmdlet.    Let's see how to do those via PowerShell, or Administration Shell. I will be keep adding commands as you comment to this article.

Send Mail with Attachment From Navision.

Hi all, We have seen how to save a report into PDF and how to send mail to a customer. Let's link these two post in one i.e. Mailing statement to a customer into PDF Format. This article is part of the Series. Please Refer  Table of Content here . If you have the old objects set let me brief you what I will be changing - 

MSDYN365BC - Data Upgrade To Microsoft Dynamics 365 Business Central on premises.

Hi Readers, We have already talked about the number of steps for upgrading to Business Central on Premises from different NAV versions. After that article, I received multiple requests for an article which list down steps for Data Migration. In this article, we will discuss steps of data migration to MSDYN365BC (on-Prem) from NAV 2017. For this article, I am considering a Cronus Demo Database without any customization. For an actual upgrade project, we will have to complete object merge using compare and Merge process. After the Merge Process, the next step is data migration. Let's discuss those steps. Direct Upgrade to Microsoft Dynamics 365 Business Central (on-Prem) is from following versions - 1. NAV 2015. 2. NAV 2016. 3. NAV 2017. 4. NAV 2018.