Skip to main content
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
  • T_Mauser Profile Picture
    397 User Group Leader on at
    RE: Send email using email message

    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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: Send email using email message

    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.

  • Amit Bansal Profile Picture
    55 on at
    RE: Send email using email message

    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
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: Send email using email message

    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
    RE: Send email using email message

    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
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: Send email using email message

    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?

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

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans