Sending Email from Wave 2 2020
Some time ago I wrote how to send emails with an attachment from the cloud version (the article you can find here: Sending emails in the Cloud).
So why the post? What had happened? Those who know Business Central or NAV (or even Navision) they think – what could change about sending e-mails? SMTP Setup is there for ages. Set it once works for years.
But it changed – a lot!
In version 17.1 Microsoft introduced quite big functionality for handling emails from Business Central. You can switch it on and off on the Feature Management page. But in a year (Q4 2021) it will become a new standard for all. Also, (if it is not already) I would recommend to switch it on for all new customers. It gives a lot of new capabilities.
Set up Emails and Scenarios
Before trying it, remember to switch on the new feature, otherwise, you will see a message like this
If you would go to SMTP Mail Setup, then you will see the notification that it was replaced.
Instead of the former setup, you should try to find the Set Up Email page (or Email Accounts page). There you can find out that instead of only one e-mail address (which was annoying in the past), now you can set up many e-mails accounts.
Moreover, you are not limited only to the SMTP setup anymore, but you can also use Microsoft 365 mailboxes or Current User as sender. If you want also there is a possibility to extend the list with your own email provides. The setup is very well described on Microsoft Docs so will not go thru it here. Go to: Set up email in Business Central – Business Central | Microsoft Docs
But why have many mails? The new concept which is called the Email Scenarios allows assigning proper scenarios to the particular email address. In other words: now you can specify from which address is sent which email. For example, the sales documents will be sent from one account and service documents from another.
If you have your unique scenario you can add the enum extension to extend the list.
Sending E-mails from the code
There are few new very useful functions in the Email codeunit which can be used for sending emails. Check the documentation for more details here: Email Module on GitHub. Below I will just show a few basic which you can use. For the email body, I will use the Word Layout report.
Send vs Enqueue
You can use one of those two functions to send emails. The difference is that the Send function works in the current session and Enqueue works in the background.
Here is an example that I used to prepare the email and send it in the current session.
To enqueue it I just need to change one line.
Show the editor
If you just want to show the editor to the user before sending the email that is also possible now. For that instead of the Send or Enqueue function in my example, I can use the function OpenInEditorModally.
Notice how the editor looks now – finally, we have support for formatting the text. I heard that in the future such editor will be allowed on other pages as well – but now it can be seen only on the email page.
When you leave the editor you can save the email as a draft and it will land in the Outbox from where you later can delete it or send. You will also find there any errors if occurs during sending.
Sent emails
An awesome feature for me is that you do not need to do any log of sent mails anymore. It is build-in now. If you will go to the Sent Emails page you can see all emails which have been sent. But not only the headers also the real body of the mail. Additionally, you can edit it and resend it if needed.
Great! its been really useful. Thanx!
does anyone know how to use the rich text editor from email?
Regards
At this moment this is not possible. MS has in the backlog idea to allow to use it but not in next release.
Hi Kris, any idea how to add as attachment?
Thanks