Using Enhanced Mailing Functionality in Business Central
Introduction
With SMTP Mail being deprecated, Business Central now provides us with a new and enhanced way for writing custom logic to send emails. To use this new functionality you have to first configure Email Accounts in Business Central, which you can find here.
Pre-requisites
- Business Central v20
References
Developing with enhanced mail feature
Configuration
The new method uses the Email Message (ID: 8904) and Email (ID: 8901) Codeunits. I’ve added multiple actions below and I’ll be describing what the expected behaviour is.
This is the simple piece of code which sends an email with the specified Recipients, CCs and BCCs.
We can specify multiple recipients and dynamically as the lists are not bound by size.
We can also call a simpler version of this method, where we don’t need to specify the CC and BCC.
Using the OpenInEditor procedure of Email codeunit causes a page to be opened up where you can edit the message before you send it.
You can also add attachments or you can save the message draft.
Using the OpenInEditorModally procedure of Email codeunit causes a page to be opened up (as “RunModal”) where you can edit the message before you send it.
You can also add attachments or you can save the message draft.
SaveAsDraft procedure saves the email as a draft and you can view it in the “Email Outbox” where you can make any changes if necessary and send it directly from there.
You can also add attachments to the email directly from code.
Conclusion
Thus we saw how we can send emails in Business Central v20.
Happy Coding!