Skip to main content

Notifications

Announcements

No record found.

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

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

(0) ShareShare
ReportReport
Posted on by 44

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

  • ergun sahin Profile Picture
    ergun sahin 8,812 Super User 2024 Season 1 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
    CBNestor 44 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
    CBNestor 44 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
    ergun sahin 8,812 Super User 2024 Season 1 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
    CBNestor 44 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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,759 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,468 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans