Friday, February 19, 2010

Modify the way AX sends reports by email

This is something I've been asked multiple times, either by customers or colleagues... The standard way AX sends reports by email is not ideal.

The two big issues are:
- Using SysINetMail which uses Outlook integration and requires the user to confirm that AX is trying to send an email using their account.
- The formating of the email is just awful and lacks relevant information.

Luckily for us, the method which sends the email is available for developers to modify. It is found at: Classes/Info/reportSendMail


void reportSendMail(PrintJobSettings p1)
{
SysINetMail m = new SysINetMail();

str fileName = 'axaptareport';

if (p1.format() == PrintFormat::ASCII || p1.format() == PrintFormat::TEXTUTF8)
fileName = fileName + '.txt';
else if (p1.format() == PrintFormat::RTF)
fileName = fileName + '.rtf';
else if (p1.format() == PrintFormat::HTML)
fileName = fileName + '.htm';
else if (p1.format() == PrintFormat::PDF || p1.format() == PrintFormat::PDF_EMBED_FONTS)
fileName = fileName + '.pdf';

m.sendMailAttach(p1.mailTo(),p1.mailCc(), p1.mailSubject(),'axapta report', true, p1.fileName(), fileName);
}



From here, instead of using SysINetMail we could use SysMailer or even System.Net.Mail. We can also change the subject, body, attachment name, etc...