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 Email ID using Email Message Codeunit - BC V19

(0) ShareShare
ReportReport
Posted on by 256

Hi All,

Below
"SMTP Mail Setup" and "SMTP Mail" are set for Mark for removal in business central.
I have one question when I upgrade the code regarding E-mail.
I have used the below object Codeunit "Email Message" and Email.
but I have did not find any way to change from name and From address while using the below function accordingly new object
"Email Message".Create(ToRecipients: List of [Text], Subject: Text, Body: Text, HtmlFormatted: Boolean, CCRecipients: List of [Text], BCCRecipients: List of [Text])
but in the Previous object function, we can change the from name and From address value.
like.
"SMTP Mail".CreateMessage(FromName: Text, FromAddress: Text, Recipients: List of [Text], Subject: Text, Body: Text, HtmlFormatted: Boolean)
I want to send mail according to the salesperson's email [FromAddress]. salesperson are many and we can not set many email accounts in business central.
Is that any way we can achieve it using "Email Message".Create(ToRecipients: List of [Text], Subject: Text, Body: Text, HtmlFormatted: Boolean, CCRecipients: List of [Text], BCCRecipients: List of [Text])
I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,111 Moderator on at

    In the latest versions BC is using E-mail scenarios. So you can define different senders addresses for different e-mail scenarios.

    docs.microsoft.com/.../admin-how-setup-email

    So when you send e-mail from code you can decide what e-mail scenario to use when you send so thereby defining the a-mail account that is used as sender

    The email codeunit has a send methode that takes your message and your e-mail scenario as parameters like this:

    Email.Send(Emailmessage, "email scenario"::"Sales Invoice");

    Here i am using the Sales Invoice email scenario.

    The email scenario is an enum that is extenable if you need more email scenarios than the standard system provieds.

  • NeoMatrix Profile Picture
    256 on at

    Thanks for Reply. Yes we can add "email scenario". But In My Case I have customize email code on button. I have to send Email to Customer and the From email id must be on Salesperson email id. And there is lot of salesperson code and not feasible to setup email account and if new sales person add we need to setup email account. SO is there any event or we can set From email id using email message

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,111 Moderator on at

    Using the email codeunit you basically have 3 options of controlling the sender address:

    (19.1.31886.32760), 'Send(Codeunit "Email Message", Enum "Email Scenario")' defined in Codeunit 'Email' by the extension System Application by Microsoft (

    19.1.31886.32760), 'Send(Codeunit "Email Message", Record "Email Account")' defined in Codeunit 'Email' by the extension System Application by Microsoft

    (19.1.31886.32760), 'Send(Codeunit "Email Message", Guid, Enum "Email Connector")' defined in Codeunit 'Email' by the extension System Application by Microsoft

    So either email scenario, Email account or Email connector.

    So best practice  and my recommendation would be to go with one of these options. 

    You have some events in the Email table that might be useful but they might break some security  rules on your mail service so you might end up with email not being sent anyway. 

  • NeoMatrix Profile Picture
    256 on at

    Hi Inge M. Bruvik, could you show the sample code for  "Send(Codeunit "Email Message", Record "Email Account")". How i can use "Email Account" record and Pass the to  the function.Send(Codeunit "Email Message", Record "Email Account")

  • Nick Webb Profile Picture
    891 on at

    Did you ever reach a satisfactory solution to this one? If yes, please give brief description?

  • Ganesh2002 Profile Picture
    56 on at

    I am having the same issue. I tried both Email Accounts and Email Scenarios. We want to use SMTP for job queues. It is set as default. We have a custom code that sends notification outside of our company (when the button is clicked). We want to send it from the "Current User".  It is not working. It is still sending from SMTP I created a new scenario and assigned it to the current user.  

    lEmailCu.Send(lEmailMessageCu, "Email Scenario"::"Dispatch Tech");

    pastedimage1660233561255v1.png

  • Ganesh2002 Profile Picture
    56 on at

    I am having the same issue. I tried both Email Accounts and Email Scenarios. We want to use SMTP for job queues. It is set as default. We have a custom code that sends notification outside of our company (when the button is clicked). We want to send it from the "Current User".  It is not working. It is still sending from SMTP I created a new scenario and assigned it to the current user.  

    lEmailCu.Send(lEmailMessageCu, "Email Scenario"::"Dispatch Tech");

    2772.pastedimage1660233561255v1.png

  • Ganesh2002 Profile Picture
    56 on at

    I am having the same issue. I tried both Email Accounts and Email Scenarios. We want to use SMTP for job queues. It is set as default. We have a custom code that sends notification outside of our company (when the button is clicked). We want to send it from the "Current User".  It is not working. It is still sending from SMTP I created a new scenario and assigned it to the current user.  

    lEmailCu.Send(lEmailMessageCu, "Email Scenario"::"Dispatch Tech");

    4744.pastedimage1660233561255v1.png

  • Ganesh2002 Profile Picture
    56 on at

    I am having the same issue. I tried both Email Accounts and Email Scenarios. We want to use SMTP for job queues. It is set as default. We have a custom code that sends notification outside of our company (when the button is clicked). We want to send it from the "Current User".  It is not working. It is still sending from SMTP I created a new scenario and assigned it to the current user.  

    lEmailCu.Send(lEmailMessageCu, "Email Scenario"::"Dispatch Tech");

  • Ganesh2002 Profile Picture
    56 on at

    My sincere apologies. I had some issue with the browser. It got posted multiple times. 

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 2,092

#2
YUN ZHU Profile Picture

YUN ZHU 663 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 515

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans