Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

How to Change From Email ID using Email Message Codeunit - BC V19

Posted on by 240

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])
Categories:
  • Ganesh2002 Profile Picture
    Ganesh2002 12 on at
    RE: How to Change From Email ID using Email Message Codeunit - BC V19

    I am having a similar issue. We want to use the default SMTP email for job queues. We have a custom code that sends email notifications (outside our company when the button is clicked). We want to send it from the user's account. I tried both Email Accounts and created a new scenario for the Current User. It is not working. It is still sending it from our default account.

  • Ganesh2002 Profile Picture
    Ganesh2002 12 on at
    RE: How to Change From Email ID using Email Message Codeunit - BC V19

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

  • Ganesh2002 Profile Picture
    Ganesh2002 12 on at
    RE: How to Change From Email ID using Email Message Codeunit - BC V19

    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
    Ganesh2002 12 on at
    RE: How to Change From Email ID using Email Message Codeunit - BC V19

    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
    Ganesh2002 12 on at
    RE: How to Change From Email ID using Email Message Codeunit - BC V19

    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
    Ganesh2002 12 on at
    RE: How to Change From Email ID using Email Message Codeunit - BC V19

    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

  • Nick Webb Profile Picture
    Nick Webb 659 on at
    RE: How to Change From Email ID using Email Message Codeunit - BC V19

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

  • NeoMatrix Profile Picture
    NeoMatrix 240 on at
    RE: How to Change From Email ID using Email Message Codeunit - BC V19

    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")

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,744 Moderator on at
    RE: How to Change From Email ID using Email Message Codeunit - BC V19

    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
    NeoMatrix 240 on at
    RE: How to Change From Email ID using Email Message Codeunit - BC V19

    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

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,570 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,683 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans