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
Note that this forum is about Dynamics 365 Finance. Please ask questions about AX 2012 in the Dynamics AX forum.
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
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.
André Arnaud de Cal...
292,031
Super User 2025 Season 1
Martin Dráb
230,868
Most Valuable Professional
nmaenpaa
101,156