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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Send email in X++ using email templates

(1) ShareShare
ReportReport
Posted on by 2

There Is a Blog to implement this, I am attaching link to open 

https://dynamicsaxinsight.com/2019/01/30/d365-send-email-in-xpp-using-email-templates/

I don't know how to add the code given in blog like just make classes or extend standard classes, can anyone help with that

I have the same question (0)
  • Arunraj Rajasekar Profile Picture
    1,743 on at

    Hi Sachin,

    Can you explain your business requirement? It will be easier to explain what needs to be changed based on that.

  • Sachin Mittal Profile Picture
    2 on at

    my requirement is that have to add email template according to the requirement given, right now I don't have a specific requirement, currently I am using a sample to establish it and not getting how it can be done

    community.dynamics.com/.../how-use-email-template-from-print-managment-to-send-email-to-the-customer

  • Suggested answer
    Arunraj Rajasekar Profile Picture
    1,743 on at

    Please take a look at the below link, it might be helpful.

    http://elandax.blogspot.com/2019/03/how-to-send-email-email-template.html

  • Sachin Mittal Profile Picture
    2 on at

    hi but, here issue remains same where to add these codes, it won't work

  • Suggested answer
    Arunraj Rajasekar Profile Picture
    1,743 on at

    I've broken down the code for clarification.

    The email template information is stored in the SysEmailTable and SysEmailMessageTable. The code below recognises the template based on the template id and saves the email subject and body as a string.


    SysEmailTable        sysEmailTable        = SysEmailTable::find('MyTemplate');
    SysEmailMessageTable sysEmailMessageTable = SysEmailMessageTable::find(sysEmailTable.EmailId, sysEmailTable.DefaultLanguage);
                    
    str messageBody = sysEmailMessageTable.Mail;
    str subject = sysEmailMessageTable.Subject;
    
    Map placeholderMap = new Map(Types::String, Types::String);
    
    placeholderMap.insert("UserName", "Evaldas Landauskas");
    
    
    messageBody = SysEmailMessage::stringExpand(messageBody, placeholderMap);
    subject     = SysEmailMessage::stringExpand(subject, placeholderMap);

    Once you have the email subject and message, insert them into the 'SysOutgoingEmailTable' and 'SysOutgoingEmailData' table like shown below.

    Records inserted in the sysoutgoingemailtable are proccessed automatically in batch.

    SysOutgoingEmailTable   outgoingEmailTable;
    SysOutgoingEmailData    outgoingEmailData;
            
    outgoingEmailTable.EmailItemId                  = EventInbox::nextEventId();
    outgoingEmailTable.TemplateId                   = sysEmailTable.EmailId;
    outgoingEmailTable.Sender                       = sysEmailTable.SenderAddr;
    outgoingEmailTable.SenderName                   = sysEmailTable.SenderName;
    outgoingEmailTable.Recipient                    = 'receiver@test.com'; //To email address
    outgoingEmailTable.Subject                      = subject; 
    outgoingEmailTable.Message                      = messageBody;
    outgoingEmailTable.Priority                     = sysEmailTable.Priority;
    outgoingEmailTable.WithRetries                  = true;
    outgoingEmailTable.RetryNum                     = 0;
    outgoingEmailTable.UserId                       = curuserid();
    outgoingEmailTable.Status                       = SysEmailStatus::Unsent;
    outgoingEmailTable.LatestStatusChangeDateTime   = DateTimeUtil::getSystemDateTime();       
    outgoingEmailTable.insert();
    

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 540 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans