Issue in Attaching a report, while sending E-mail

Hi,

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);

interopPermission.assert();

mail = new SysMailer();

mail.SMTPRelayServer(SysEmailParameters::find(false).SMTPRelayServerName);

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

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

mail.tos().appendAddress(vendTable.Email);

mail.priority(#priorityValue); // 2

// Build the Message

mail.htmlBody(#mailBody + #newline);

mail.subject(#mailSubject);

mail.attachments().add(fileName);

//mail.attachments().add(strReplace(fileName,#backSlash,#forwardSlash));

mail.sendMail();

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.

mail.attachments().add(fileName);

//mail.attachments().add(strReplace(fileName,#backSlash,#forwardSlash));

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;

;

try

{

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

perm = new InteropPermission(InteropKind::ComInterop);

perm.assert();

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;

argsPOS.record(custInvJour);

argsPOS.name(reportstr(SalesInvoicePDF));

reportPOS = Classfactory.reportRunClass(argsPOS);

reportPOS.setTarget(PrintMedium::File);

reportPOS.printJobSettings().format(PrintFormat::PDF);

reportPOS.printJobSettings().fileName(fileName);

reportPOS.init();

reportPOS.run();

//for attachments and sending mail

_sendMail = new Sysmailer();

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

_sendMail.fromAddress(‘SMTPusername’);

_sendMail.tos().appendAddress(‘tomailid’);

_sendMail.attachments().add(fileName);

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

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

_sendMail.sendMail();

CodeAccessPermission::revertAssert();

}

catch(Exception::Internal)

{

throw Exception::Internal;

}

}

you better ask your admin for the credentials.

Thanks & Regards,

Britto John Baskar.A