Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

To, CC, BCC recipients while sending emails using X++

(1) ShareShare
ReportReport
Posted on by 21
Hi community,
 
I am working on a requirement where I need to send emails to people using To, CC and Bcc recipients.
 
One solution that I see is to use SMTP client to send using X++, but we are having some technical issues with our SMTP server.
 
Second, If I want the email distributor batch to send my email using the selected email provider (SMTP/Graph/Exchange), how can I specify the cc and Bcc emails while creating a record in the SysOutgoingEmailTable?
 
Third, If I want to send email using Graph, how to do it in X++, and will it allow me to specify the To, cc and Bcc emails?
 
Thanks in advance.
 
  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    To, CC, BCC recipients while sending emails using X++
    SysMailer class doesn't exist in D365FO.
     
    Instead, you can use classes like SysMailerSMTP or SysMailerExchange, but the recommended (extensible) approach is creating an instance through SysMailerFactory, as I demonstrated in the blog post.
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 14,202 Super User 2025 Season 1 on at
    To, CC, BCC recipients while sending emails using X++
    Hi @Sohan,
     
    you can use SysMailerMessage et SysMailer classes.
     
    e.g.
    void sendEmail()
    {
      str senderEmail = "sender@example.com";
      str recipientEmail = "recipient@example.com";
      str subject = "Hello";
      str body = "This is the email body.";
    
      SysMailer mailer = SysMailer::construct();
      SysMailerMessage message;
    
      message.setFromAddress(senderEmail);
      message.addToAddress(recipientEmail);
      message.addCc("cc@exemple.com");
      message.addBcc("bcc@exemple.com");
      message.setSubject(subject);
      message.setBody(body);
      mailer.sendEmail(message);
    
    }
    Best regrads,
    Mohamed Amine MAHMOUDI
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    To, CC, BCC recipients while sending emails using X++
    You don't have to use the email distributor batch to use the other email providers. Look at How to send emails from code in AX 7, where I explained providers and showed code for constructing and sending a message. If you don't want to change your default provider, you can construct a specific one in code.

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans