Send email from AX using exchange servers

There are number of posts to sent emails from AX using Hotmail(Live) or gmail exchange server. This is really helpful when we don’t have exchange is in place due to high cost or you just want to send emails for testing or demo purpose, so in this case we can use this method .

To achieve this requirement go to System Administration | Setup | System | E-mail parameters

P.S. I am using a dedicated email account at outlook (Hotmail) domain for this example.

Email parameters


Here is the job I wrote to send email for selected user. I name it SendTextMail as in my following post I will be writing to send invitation from AX using Hotmail or Gmail exchange server.


staticvoid SendTextMail(Args _args)


System.Net.Mail.MailMessage             mailMessage;

System.Net.Mail.SmtpClient              myMail;

System.Net.Mail.MailAddressCollection   mailcoll;

System.Net.Mail.MailAddress             mailFrom;

System.Net.Mail.MailAddress             mailTo;

System.Net.Mail.MailAddress             mailCC;

str                                     receiverMailAddress;

str                                     mailBody;

str                                     smtpServer;

str                                     mailSubject;

str                                     CcMailAddress;

int                                     SMTPPort;


str                                     mail;

str                                     pwd;

Dialog dialog = new Dialog(‘Email’);

Dialogfield     person, emailSubject, emailBody;

HcmWorker       hcmWorker;

UserInfo        userInfo;

DirPersonUser   dirPersonUser;

SysUserInfo     sysUserInfo;

SysEmailParameters parameters;

// dialog field to select user to whom email will be send

person          = dialog.addField(extendedTypeStr(HcmWorkerRecId ), ‘Person :’ );

emailSubject    = dialog.addField(extendedTypeStr(Description), ‘Subject :’ );      // Email Subject

emailBody       = dialog.addField(extendedTypeStr(Notes), ‘Body :’ );               // Email Body



parameters = SysEmailParameters::find();   // Find values from Email Parameters

new InteropPermission(InteropKind::ClrInterop).assert();

        // gets HcmWorker record based on person selected from user dialog

hcmWorker = hcmWorker::find(person.value());

if(!hcmWorker.RecId)   // Verify either user exist or not


throw error(‘User not found’);


selectfirstOnly dirPersonUser

join userInfo

where dirPersonUser.PersonParty == DirPartyTable::findByName( && == dirPersonUser.User;

selectfirstOnly sysUserInfo

where sysUserInfo.Id ==;      // Retrieve user info record for selected user

mailSubject         = emailSubject.value();

mailFrom            = new  System.Net.Mail.MailAddress(parameters.SMTPUserName ,”Name”);

mailTo              = new  System.Net.Mail.MailAddress(sysUserInfo.Email);

//mailTo            = new  System.Net.Mail.MailAddress(“”);

//mailCC            = new  System.Net.Mail.MailAddress(“”;

mailcoll            = new  System.Net.Mail.MailAddressCollection();

mailBody            = emailBody.value();



            // using the SMTP server ip //setup in email Parameters

smtpServer          = SysEmaiLParameters::find(false).SMTPRelayServerName;

mailMessage         = new System.Net.Mail.MailMessage(mailFrom,mailTo);



SMTPPort            = SysEmaiLParameters::find(false).SMTPPortNumber;

myMail              = new System.Net.Mail.SmtpClient(smtpServer, SMTPPort);

           // For SSL enabled mail servers. Ex: gmail,, port 465 or 587


pwd = SysEmaiLParameters::password();

mymail.set_Credentials(New System.Net.NetworkCredential(parameters.SMTPUserName, pwd));





throw Exception::CLRError;






After running this job You will get this UI from where you will select person , Subject of email . and Body of email to sent click OK.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s