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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Send Emails to multiple recipients with SysEmailSystemTable by X++ AX2012

(0) ShareShare
ReportReport
Posted on by 46

Hi all,

I am kinda new with batch processing and emails, so I would like you guys to give me a hand with this.

I have a code that calculates the prices of production against the sales orders. If the Productions costs > Sales order then pulls a trigger by code and send Email to specifics recipients.

I have configurated the basics stuff like email parameters and templates. And my code is actually sending the emails into the waiting stack ( ) . but only sends the actual email only if I pressed the ok button in the batch job. where Do I configure it in order to send emails directly after the trigger is pulled (just at the moment the code sends the email).

also How Do I sent to multiple recipients using the SysEmailSystemTable::sendMail()

here the code

8713.pastedimage1621324940616v2.png

I have the same question (0)
  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Send Emails to multiple recipients with SysEmailSystemTable by X++ AX2012

    Actually, I tried to say the same thing, but I guess I couldn't express it enough.
    "SysEmailSystemTable :: sendMail" takes "sendto" as the 3rd parameter, but the structure is built on a single receiver. All you have to do is add the following code, that I got from your example, to the structure that the system uses to send mail. (SysMailerNet if I remember correctly)

    toAddr = strSplit(toAddress,",");//you can use ;
    lenum = toAddr.getEnumerator();
    
    while(lenum.moveNext())
    {
        mailer.tos().appendAddress(lenum.current());
    }

    Glad you solved the problem. For situations where the Ax template cannot be dispensed with, I wanted this information to be here as a note.

  • Suggested answer
    CBNestor Profile Picture
    46 on at
    RE: Send Emails to multiple recipients with SysEmailSystemTable by X++ AX2012

    Well I found the way.

    I wanted to use the AX framework with template and traceability but unfortunately is not accepting CSS inside the HTML.. which is what bothers mi most.

    So I use this code instead, which I found from internet. if the Email is already setup in the AX then this works for everyone:

    private void sendMail_HTML(str _msgBoxHtmlTable)
    {
           SysMailer mailer;
        SysEmailParameters parameters = SysEmailParameters::find();
        SMTPRelayServerName relayServer;
        SMTPPortNumber portNumber;
        SMTPUserName userName;
        SMTPPassword password;
        Str subject,body, bodyBig;
        InteropPermission interopPermission;
    
        System.Exception e;
    
        List toAddr;
        ListEnumerator lenum;
        str toAddress = "recipient1@test.tst , recipient2@test.tst";
        //str filePathName = @"C:\Path\filename.xlsx";
    
    
        if (parameters.SMTPRelayServerName)
        relayServer = parameters.SMTPRelayServerName;
        else
        relayServer = parameters.SMTPServerIPAddress;
        portNumber = parameters.SMTPPortNumber;
        userName = parameters.SMTPUserName;
        password = SysEmailParameters::password();
        subject = "Produktion: "   prodTable.ProdId;
        
        bodyBig =
    "" 
    "                            " 
    "                            " 
    "                                " 
    "                            " 
    "                            " 
    "                                " 
    "                                " 
    "                            " 
    "                            " 
    "                                " 
    "                                " 
    "                            " 
    "                            " 
    "                                " 
    "                                " 
    "                            " 
    "                            " 
    "                                " 
    "                                " 
    "                            " 
    "
    Invoice:01-Nestor
    Item:010058-001
    Invoiced:289.47 PLN
    Purchased:28.95 PLN
    Difference:260.52 PLN
    "; try { interopPermission = new InteropPermission(InteropKind::ComInterop); interopPermission.assert(); mailer = new SysMailer(); mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM); //instantiate email mailer.fromAddress("fromAdress@ax.dk","From Name"); toAddr = strSplit(toAddress,","); lenum = toAddr.getEnumerator(); while(lenum.moveNext()) { mailer.tos().appendAddress(lenum.current()); } mailer.subject(subject); mailer.htmlBody(bodyBig); //mailer.attachments().add(filePathName); mailer.sendMail(); CodeAccessPermission::revertAssert(); info("Email has been sent!"); } catch (Exception::CLRError) { e = ClrInterop::getLastException(); while (e) { info(e.get_Message()); e = e.get_InnerException(); } CodeAccessPermission::revertAssert(); info ("Failed to Send Email "); } }

    Always end up finding the answers here

  • CBNestor Profile Picture
    46 on at
    RE: Send Emails to multiple recipients with SysEmailSystemTable by X++ AX2012

    Hi Ergun.

    thanks for the reply. but I am afraid I am still the same...

  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Send Emails to multiple recipients with SysEmailSystemTable by X++ AX2012

    I haven't dealt with e-mails for a long time, but I have one or two pieces of information left in my mind.

    First, I guess we could add more than one "to" on the SysMailer (the mail structure basically uses), but not on the SysEmailSystemTable (I might be confusing with cc)

    Latter; we were adding to the messageBody in sendmail to create a dynamic html table. (I remember converting to html and adding in the loop, but it could be a different mailing class)

    Note:The information is unclear and I don't have time to confirm it right now, I shared it to give an idea.

  • CBNestor Profile Picture
    46 on at
    RE: Send Emails to multiple recipients with SysEmailSystemTable by X++ AX2012

    I managed to configure the batch... It was not working until I closed the Ax client and opening again... now is sending every 2 minutes..

    Now I am missing about sending to multiple recipients. And If I also may ask; How to build a HTML dynamically (like a table) and send it from code.. I know that I can use Placeholders but here I need to build the table depending on the numer of rows from X++

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 777 User Group Leader

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 602 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans