Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to send multiple attachments through SysMailer

(0) ShareShare
ReportReport
Posted on by 362

Hello Everyone,

Can we attach multiple files using SysMailer class ? Below is the code sample am using to send the email, where i need to send multiple files as attachment\

mailer = New SysMailer();
mailer.fromAddress(SysEmailTable::find(EmailId).SenderAddr,SysEmailTable::find(EmailId).SenderName);
mailer.tos().appendAddress(_documentsDetailsTmp.EmailId);

EmailCC = strFmt("CustOps@power.com;%1",worker.email());
splitEmailCC = strSplit(EmailCC,";");
lenum = splitEmailCC.getEnumerator();
while(lenum.moveNext())
{
mailer.ccs().appendAddress(lenum.current());
}

//Subject
message = SysEmailMessageTable::find(EmailId, LanguageId).Subject;
message = SysEmailMessage::stringExpand(message,mappings);
mailer.subject(message);

//Body
messageBody = SysEmailMessageTable::find(EmailId, LanguageId).Mail;
messageBody = SysEmailMessage::stringExpand(messageBody, SysEmailTable::htmlEncodeParameters(mappings));
messageBody = strReplace(messageBody, '\n', '<br>');
mailer.htmlBody(messageBody);

//Send Email
mailer.SMTPRelayServer(SysEmailParameters::find().SMTPRelayServerName,
SysEmailParameters::find().SMTPPortNumber,
SysEmailParameters::find().SMTPUserName,SysEmailParameters::password(),
SysEmailParameters::find().NTLM);
mailer.attachments().add();                               //Using this, we can send one file as attachment

mailer.sendMail();

Please help me to understand, how can we send multiple files. Thank you in advance !!

Regards,

Venkat

  • Martin Dráb Profile Picture
    Martin Dráb 231,305 Most Valuable Professional on at
    RE: How to send multiple attachments through SysMailer

    Note that this forum is about Dynamics 365 Finance. Please ask questions about AX 2012 in the Dynamics AX forum.

  • Venkatdax0 Profile Picture
    Venkatdax0 362 on at
    RE: How to send multiple attachments through SysMailer

    Thank you Martin, yes the query is for AX 2012 and after adding attachments().add() multiple times it is working.

    And, will use rich formatting to paste my code from next time :p

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,305 Most Valuable Professional on at
    RE: How to send multiple attachments through SysMailer

    My F&O does not contain SysMailer class at all. Aren't you talking about AX 2012 or something? Or didn't somebody port SysMailer from older versions?

    This is how you can write your code in F&O:

    SysMailerMessageBuilder builder = new SysMailerMessageBuilder();
    builder.setFrom((SysEmailTable::find(emailId).SenderAddr, SysEmailTable::find(emailId).SenderName);
    builder.addTo(_documentsDetailsTmp.EmailId);
    builder.addCc('CustOps@power.com');
    builder.addCc(worker.email());
    
    //Subject
    str subject = SysEmailMessageTable::find(EmailId, LanguageId).Subject;
    subject = SysEmailMessage::stringExpand(subject, mappings);
    builder.setSubject(subject);
    
    //Body
    messageBody = SysEmailMessageTable::find(EmailId, LanguageId).Mail;
    messageBody = SysEmailMessage::stringExpand(messageBody, SysEmailTable::htmlEncodeParameters(mappings));
    messageBody = strReplace(messageBody, '\n', '
    '); builder.setBody(messageBody, true); //builder.addAttachment(...) //builder.addAttachmentFromFile(...) SysMailerFactory::sendNonInteractive(builder.getMessage());

    If you indeed meant an older version, and therefore you want to use SysMailer, did you try calling attachments().add() multiple times (for different files)? It should work.

    By the way, please use Insert > Insert Code (in the rich formatting view) to paste source 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…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans