Issue in Attaching a report, while sending E-mail


I am generating a report, and mailing it to the the vendors in AX 2009.

When i mail from the the client side (Class running on server side) - No issues.

But my requirement is send the mail from server side.

Some times i am getting the error message

"Method ‘send’ in COM object of class ‘CDO.Message’ returned error code 0x80040211 () which means: ".

While attaching sometimes it is taking the backward slash in the file path , sometimes forward slash. i am not getting when i need to give forward slash and backward slash.

Here is my code, (Class Running in server side)

void sendMail(LedgerJournalTrans _journalTrans)


SysMailer mail;

InteropPermission interopPermission;


interopPermission = new InteropPermission(InteropKind::ComInterop);


mail = new SysMailer();


mail.fromAddress(Setup.SenderMailId); // Sender mail id

vendTable = VendTable::find(_journalTrans.AccountNum);


mail.priority(#priorityValue); // 2

// Build the Message

mail.htmlBody(#mailBody + #newline);





info(strfmt("@xyz1406",_journalTrans.AccountNum)); // Payment Advice Report is generated and mail is sent to the Vendor %1


These are the two lines causing the error, i couldnt get which one to use when my code is running in server side.



Thanks & Regards,

Arun B S

Hi Arun,

I too got the same error and i found that the error is related to SMTP user name and password.

I provided wrong password for my SMTP user name.I provided the correct on and it’s working fine with attachment.

Please find the below code which i used to send amil with an attachment

static void sendMail()


CustInvoiceJour custInvoiceJour;

Args args = new Args();

CustInvoiceJour custInvJour;

InvoiceId _Invoiceid;

SalesId _salesId;

Email mailid,mailid1;

PrintJobSettings printJobSettings = new PrintJobSettings();

SysINetMail m = new SysINetMail();

str fileName,filename1;

SysMailer _sendMail;

InteropPermission perm;

ReportRun report;

RecordSortedList List = new RecordSortedList(62);

Args argsInv= new Args();

Args argsPOS= new Args();

Reportrun reportInv;

Reportrun reportPOS;




fileName = DocuParameters::find().ArchivePath + “\test.pdf”;

perm = new InteropPermission(InteropKind::ComInterop);


custInvoiceJour = CustInvoiceJour::findRecId(5637151333);

_Invoiceid = custInvoiceJour.InvoiceId;

_salesId = custInvoiceJour.SalesId;

select custInvJour where custInvJour.InvoiceId == custInvoiceJour.InvoiceId;

//for creating first pdf file for salesinvoice Report

mailid = CustTable::find(custInvoiceJour.OrderAccount).Email;


reportPOS = Classfactory.reportRunClass(argsPOS);





//for attachments and sending mail

_sendMail = new Sysmailer();

_sendMail.SMTPRelayServer(‘SMTP server name’,25,‘SMTPusername’,‘SMTP Password’,false);




_sendMail.subject(‘Subject — Test mail’);

_sendMail.htmlBody(‘Please Find the Attached Sales Invoice’);






throw Exception::Internal;



you better ask your admin for the credentials.

Thanks & Regards,

Britto John Baskar.A