Email helper class to send email with attachment in Dynamics 365 finance and operations
Views (18)
Its very basic need from customers to send email with attachments for any implementation projects, hope the below helper class will be useful in this case.
////// email helper class to send email with attachment /// public class EmailHelperClass { public static boolean sendEmail(str _fromEMail, str _toEmail, sysEmailSubject _subject, str _body, str _ccEmail = "", FileName _filename ="", System.IO.Stream _stream = null) { System.Exception exception; try { var messageBuilder = new SysMailerMessageBuilder(); messageBuilder.addTo(_toEmail) .setSubject(_subject) .setBody(_body); if (_ccEmail) { messageBuilder.addCc(_ccEmail); } if (_fromEMail) { messageBuilder.setFrom(_fromEMail); } if (_stream != null) { messageBuilder.addAttachment(_stream,_filename); } SysMailerFactory::sendNonInteractive(messageBuilder.getMessage()); } catch (Exception::CLRError) { exception = CLRInterop::getLastException(); info(strFmt("@SCM:EmailNotSentSetupInstruction", exception.ToString())); } return true; } }
Hope this helps!, I will come with another interesting blog post!

Like
Report
*This post is locked for comments