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, ...
Answered

How to send multiple attachments through SysMailer

(0) ShareShare
ReportReport
Posted on by 364

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

I have the same question (0)
  • Martin Dráb Profile Picture
    236,172 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
    364 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
    236,172 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,352

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 616 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans