Email the attachement using x++ code in D365FO via SysMailerMessageBuilder

Hi All,

I have added one attachment (.pdf file)to the Site ‘A’ and i want to email this attachment using code. To email the attachment i have used the following code but i get the attachment in unknown format. Please suggest me how can i resolve this?

InventSite site = InventSite::find('A');
DocuRef docuRef;
DocuValue docuValue;

SysMailerMessageBuilder mailer = new SysMailerMessageBuilder();
SysMailerSMTP smtp = new SysMailerSMTP();

docuRef = DocuRef::findTableIdRecId(curExt(), tableNum(InventSite), site.RecId);

mailer.setSubject("Testing Attachment");

mailer.addAttachment(DocumentManagement ::getAttachmentStream(docuRef),docuRef.Name);


Thanks in advance…

Can you please elaborate what you mean by “i get the attachment in unknown format”?

You can specify MIME type in the third argument of addAttachment(), but without understanding your problem, I can’t say whether it would make a difference.

Please tell how can i add MIME type to the existing code to send as .pdf file

As I said, it’s the third argument of addAttachment(), i.e. it would come after docuRef.Name at line 16.

But it’s impossible to say whether it has anything to do with your problem without more information about the problem.

I got the attachemt as type file. But I want it as .pdf file