To send an email with multiple recipients using AL code in Microsoft Dynamics 365 Business Central, you can utilize the `EmailMgt` codeunit and the `Send` function. Here's an example of how you can achieve this:
```AL
PROCEDURE SendEmailWithMultipleRecipients@1()
VAR
EmailMgt@1: Codeunit 400;
EmailMessage@2: Record 441;
Recipients@3: Record 442;
BEGIN
EmailMessage.INIT;
EmailMessage.Subject := 'Test Email';
EmailMessage.Body := 'This is a test email sent to multiple recipients.';
Recipients.INIT;
Recipients."E-mail" := 'recipient1@example.com';
Recipients.Insert;
Recipients."E-mail" := 'recipient2@example.com';
Recipients.Insert;
Recipients."E-mail" := 'recipient3@example.com';
EmailMgt.Send(EmailMessage, Recipients);
END;
```
In this example, we create a new email message by initializing the `EmailMessage` record and setting the subject and body of the email. Then, we initialize the `Recipients` record and insert multiple recipients by setting their email addresses. Finally, we call the `Send` function of the `EmailMgt` codeunit, passing in the `EmailMessage` and `Recipients` records.
Make sure to replace the email addresses with the actual email addresses of the recipients you want to send the email to.
Please note that you need to have the necessary email settings configured in Business Central for sending emails, such as the SMTP server details.
No comments:
Post a Comment