This blog post is tightly connected to one of my previous posts:
Ease of Upgrade
Microsoft is trying to make our life easier from an upgrade perspective with merge commandlets and upgrade codeunits. This is nice but sometimes you run into situations that are not fixable with tools like these.
I am currently upgrading one of my older customers from NAV2009R2 classic to NAV2016. Some code goes back to 3.60 and reports to 2.x.
During this upgrade I run into a number of issues that are disruptive to merge commandlets, even if I were using pages, even if I were using extensions and eventing.
Refactoring
This has everyting to do with Microsoft refactoring. There are three major application areas they have refactored that blow up my upgrade.
- Dimensions
- SMTP Email
- Excel Buffer
This post is about SMTP Email. Dimensions we all know, I don’t think I have to write more of that.
The Shortcut
To “fix” sending emails with SMTP there is a shortcut and a “new way”.
Let me show the shortcut first.
In NAV2016 the function AddAttachment has one extra parameter
Simple fix. But if you want SMTP in NAV2016 you really should use something else.
Arguments Table | 9500 Email Item
As I mentioned in my post, Microsoft is starting to use a table as a class grouping arguments in a table to pass into a function. This is called “argument tables” and described in my blog and Master Class.
Using Argument Tables | Introducing Overloading in Dynamics NAV
The example is a new table Email Item (9500) that helps you with sending emails.
Idea is to populate the fields of the table and then use the Send method.
There are advantages of using this, for example, you can enable editing the email in outlook. This is optiona.
It also has some flaws.
Defaults
One downside of working with argument tables is that you need a line of C/AL code per argument to populate.
With SMTP email you often have default sender and reply addresses such as the company name and a noreply@ address.
AppendBody
The Arguments table allows you to add a body. This is a long text. It is often usefull to populate the body line-by-line. Especially if you do HTML formatting.
The Result
The result looks something like this
EmailItem.SetDefaults; EmailItem.Subject := NotTxt.Subject + "Invoice No."; EmailItem."Send to" := "Email Address"; NotTxtLn.SETRANGE("Text Code", NotTxt.Code); NotTxtLn.SETRANGE("Text No.", NotTxt."Text No."); IF NotTxtLn.FINDSET THEN REPEAT EmailItem.AppendBodyText(NotTxtLn.Text); UNTIL NotTxtLn.NEXT = 0; EmailItem.Send(TRUE);
Please note that I also use a very old version of notifications. This was discontinued somewhere after Navision 4.0. I have to upgrade this to the new Notification. Another thing that broke my “Easy Upgrade” since it was bringing in objects with name conflicts.
Naming Issue
There is a small naming issue. “Send to” should have been “Send To”. Must have slipped code review.
Attachments
The Arguments table also does not support multiple attachements.
HTML Formatted
If you want to send your email in HTML format, you cannot open it in the UI. This is the (TRUE) parameter of the Send method.
Remember my dear students in the Master Class! UI Separation. 😉