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

VIEW SERVER STATE permission on SQL Server?

Hi all, Sometime While trying to Login into a database we face an error message as shown below. --------------------------- Microsoft Dynamics NAV Classic --------------------------- You cannot start Microsoft Dynamics NAV Classic because you do not have the VIEW SERVER STATE permission on SQL Server. Contact your system administrator. --------------------------- OK    ---------------------------

NAV 2013 R2 - Cumulative update 12 Released.

Hi all, Please find below the details of  Cumulative Update 12 released for Microsoft Dynamics NAV 2013 R2. Title - Cumulative Update 12 for Microsoft Dynamics NAV 2013 R2 Build No. - 38053 Release Date - October, 2014 Local Version Included - AU, AT, BE, CH, DE, DK, ES, FI, FR, IS, IT, NA, NL, NO, NZ, SE, UK, RU Download Link Note: Implementing this cumulative update will require a database conversion unless you have already implemented update rollup 5.

NAV 2013 Upgrade Part III - Data Upgrading.

Hi all, As per agenda we need to discuss the data upgrade in NAV 2013. The process is similar to what used to be till NAV 2009 R2 but with some changes. Let's start the process. Remember -  1) You can only upgrade a database to NAV 2013 from NAV 2009 SP1 / R2 SQL Only. 2) The Synchronization of users with SQL Server is no more required.