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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

How to change 'from address' when sending email in an AL Extension

(0) ShareShare
ReportReport
Posted on by 891

I've setup an email account in BC (type: Smtp).

I have a procedure (see code below) which is working fine except that the From Address is coming from the Email Account and not from the code below.

procedure SendEnhancedEmail()
var
recTempEmailItem: Record "Email Item" temporary;
begin
Clear(recTempEmailItem);
recTempEmailItem.Reset();
recTempEmailItem.Init();
recTempEmailItem.Initialize();
recTempEmailItem."From Address" := 'nick.webb@o-net.co.uk';  // <- This line is being ignored.
recTempEmailItem."Send to" := 'nick.webb@o-net.co.uk';
recTempEmailItem.Subject := 'This is a test subject';
recTempEmailItem.SetBodyText('This is a test body.<br>This is Line 2.');
recTempEmailItem.Insert();
recTempEmailItem.Send(true, "Email Scenario"::Default);

end;

How do I set the From Address at runtime in an AL extension?

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    Hi,

    yes in the BC if we are creating an email and sending with new email features in general we don’t have any option to modify send from address, as it pick up the from addresses from the default email account setup.

    thanks

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    You can also use the email scenarios which are ready to extend.

  • Suggested answer
    YUN ZHU Profile Picture
    95,331 Super User 2025 Season 2 on at

    Hi, I checked the source code and it looks like the "From Address" is retrieved in the Send() function.

    pastedimage1653955879276v1.png

    pastedimage1653955920694v2.png

    pastedimage1653955961978v3.png

    So, as Nitin mentioned, you should manage "From Address" in Email Scenario feature.

    More details: https://docs.microsoft.com/en-us/dynamics365/business-central/admin-how-setup-email#assign-email-scenarios-to-email-accounts

    pastedimage1653956010975v4.png

    pastedimage1653956016593v5.png

    Hope this helps as well.

    Thanks.

    ZHU

  • Nick Webb Profile Picture
    891 on at

    Thanks all for your help.

    So, what if you want to use SMTP but you still want to be able to specify the 'From Address', as we have been able to do up until the last release? The only way I can think to make it work is to create an SMTP Email Account & Scenario for each employee / user, don't specify the 'From Address' in code and pass in the Scenario in the "Email Item".Send method, which will then take the from Address from the Email Account via the scenario. Of course, seeing as the Scenarios are members of an extended Enum, a program change would be required every time a new employee is encountered. Clanky huh? Is there a better way?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans