Skip to main content

Notifications

Using the Office 365 SMTP Server to Send Emails from AX 2012 to External Email Addresses without a SMTP Relay.

If your outbound emails from AX have suddenly stopped working to external addresses you may need to change AX so that it provides a username and password when sending emails.  This can be more involved than just configuring a username and password within the AX "E-mail parameters" Setup screen.  For example attempting to use the Office 365 SMTP server "smtp.office365.com" you will quickly discover that a generic error gets logged "Method 'send' in COM object of class 'CDO.Message' returned error code".  The error is due to the other parameters that the SMTP server requires that AX does not provide.   AX does not provide the From Address nor the SSL=True flag both of which are now required by the Office 365 SMTP server. 

To get AX to successfully send emails using the SMTP server "smtp.office365.com" two methods need to be changed within the SysMailer class. 

First in smtpRelayServer add the below just before the _fields.resync(); towards the bottom:

        _fields.add(#SmtpServer,_server);
        _fields.add(#SmtpServerPort,_port);
        _fields.add('http://schemas.microsoft.com/cdo/configuration/smtpusessl',1);
        _fields.add(#SmtpAuthenticate,1);
        _fields.add(#SmtpSendUserName,_userName);
        _fields.add(#SmtpSendUserPassword,_password);

Second in sendMail add the below just before the _com.send(); towards the bottom:

_com.from(TheSameEmailAddressFromAbove);

Note that a decision needs to be made as to what configurations are going to be supported such as using NTLM to get the current user or always using the configured user above.  Based on this adjust the if logic in both of the above to conditionally set the new parameters.  Also if _userName in smtpRelayServer is the username from the "E-mail parameters" setup then in sendMail lookup this value and provide it as the value passed to "_com.from" (shown above as TheSameEmailAddressFromAbove).

Two additional pieces of technical information will help here.  First when a password is entered on the "E-mail parameters" screen it gets stored in SQL in the table SYSEMAILSMTPPASSWORD per AOS server.  Given this the password needs to be configured while connected to each AOS server to create values in the table for each server.  Secondly more detailed SMTP errors can be displayed by adding a try catch around the "_com.send" in sendMail as below which is how I discovered the missing parameters described above.

   try { _com.send(); }
    catch { checkFailed(_com.error().description()); }

Comments

*This post is locked for comments