web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Send email using email message

(0) ShareShare
ReportReport
Posted on by 55
Hi All,
 
I am trying new SMTP functionality to send emails through my AL code but it is not working. I am not sure if I am missing something. Below is my sample code:-
 
page 60181 HelloWorldExt
{
ApplicationArea = All;
Caption = 'Test Email';
UsageCategory = tasks;
trigger OnOpenPage();
begin
SendEmail();
Message('Message Send');
end;
procedure SendEmail()
var
TxtDefaultCCMailList: List of [Text];
TxtDefaultBCCMailList: List of [Text];
TxtRecipientsList: List of [Text];
begin
EmailAccount.Reset();
EmailAccount.SetFilter(Connector, 'SMTP');
if EmailAccount.FindLast() then;
TxtRecipientsList.Add('xxxx@xxxx.com');
EmaiMsg.Create(
TxtRecipientsList,
'Subject - Test Email',
'Body - This is Email Body',
false
);
EmailObj.Send(EmaiMsg, Enum::"Email Scenario"::Default);
end;
Var
EmailObj: Codeunit "Email";
EmaiMsg: Codeunit "Email Message";
EmailAccount: Record "Email Account";
}
 
Thanks,
Amit
I have the same question (0)
  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    Just by looking at your code it looks ok. But i have not tried to run it.

    Just som things to check.

    Have you defined a default scenario?

    Can you see the email you try to send in the outgoing mail queue and see what status it got there?

  • Amit Bansal Profile Picture
    55 on at

    Hi Inge,

    I didn't defined default scenario. I am not able to understand why we have to define default scenario.

    Is it required.

    Thanks,

    Amit

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    The way you have organized your code makes it necessary to define it because you have used it in your code.

    You can send the message with out using a scenario but just refer to the email account instead.

    Send(EmailMessage: Codeunit "Email Message"; EmailAccount: Record "Email Account" temporary): Boolean
    Emailobj.Send(EmailMsg;EmailAccount);
    Should work for you.
    But i think you should define your EmailAccount variable as temporary because that is compliant with the send methods signature.
  • Amit Bansal Profile Picture
    55 on at

    Thanks, Inge for quick reply. I checked "Email Outbox" and there it is giving me "Cannot authenticate the credentials on server smtp.office365.com." error. I will work with admin and correct this issue and will come back if it is still not resolved.

    Thanks,

    Amit.

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    Not an uncommon error. I think smtp connection by default is off on Office365 mail accounts. So they need to be enabled before you can use them like SMTP accounts in Business Central. We are here if you need further assistance.

  • T_Mauser Profile Picture
    401 User Group Leader on at

    I also had that problem in the beginning - solved it with adding the necessary permissions to the mail boxes.

    You can find it in the exchange admin tool:

    Mailboxes -> Mailbox Permissions ->Manage mailbox delegate -> Send as

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,690 Super User 2026 Season 1

#2
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 1,091 Super User 2026 Season 1

#3
YUN ZHU Profile Picture

YUN ZHU 1,047 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans