4/25/2017

How to email report in AX 2012 without outlook?

In out of box AX 2012, the user has to have outlook to mail the report which is kind of annoying, cause not all of the AX user has outlook. We can find code snippet to bypass outlook to do that online, but you'll notice those codes are only for the old AX report instead of SSRS report. In AX 2012,  the reports are all SSRS reports which means we cannot modify the code in Info\reportSendMail as we did for AX 2009 to bypass outlook.
In fact, it's even easier to do that in AX 2012. In AX 2012, when emailing reports, the class 'SrsReportRunMailer' is executed. What we need to do is just change that class. If you open that class, you'll see the method 'initMailer' decides whether to use SMTP or outlook. When mailing in a batch, it uses SMTP, but when emailing at client, it uses outlook. To change the logic to always go with SMTP, we only need to comment out the 'if' clause and leave the code which takes SMTP. See below,

private void initMailer()
{
    fromAddress = SrsReportRunMailer::buildFromEmailAddress();
    // Always use SMTP, never outlook.
    //if (isRunningOnServer())
    //{
        // get the mailer object
        mailer = this.parmSysMailer();

        // validate the from email addresses
        if (!fromAddress ||
            !SysEmailDistributor::validateEmail(fromAddress))
        {
            error(strfmt("@SYS134596", "@SYS4083"));
            return;
        }
    //}
    //else
    //{
        //inetMailer = new SysINetMail();
    //}