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

Announcements

News and Announcements icon
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)
  • CBNestor Profile Picture
    46 on at

    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++

  • ergun sahin Profile Picture
    8,826 Moderator on at

    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

    Hi Ergun.

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

  • Suggested answer
    CBNestor Profile Picture
    46 on at

    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

  • ergun sahin Profile Picture
    8,826 Moderator on at

    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.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 676

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 633 Super User 2026 Season 1

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 624 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans