web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Send email with X++ and a free SMTP server

(0) ShareShare
ReportReport
Posted on by

Has anyone had any success with using a free SMTP server like smtp.gmail.com or smtp.live.com to send email in Dynamics AX? 

I have a normal (not business) gmail account that I enter into the email parameters form. I use smtp.gmail.com and tried ports 587 and 465. I’ve tried with and without NTLM. We've also tried Hotmail and outlook email accounts. 

We have tried this in AX 4 and AX 2012. We run a job like the ones below; the job runs, gives no error, but no email is sent. We've checked spam folders and tried different addresses as receivers. We've pinged the smtp servers and that works from the aos server and client. 

My guess is that it does not work because there is no option to enable TLS, which both the live and gmail servers require. Is there a way to overcome this? 

 

Are we missing anything obvious? Has anyone every used a gmail/Live smtp to send email from AX?

 

-----------------------------------------------------------------------------------------------------------------------

 I don't think the problem is with the code, but I'll add it anyway. We've tried a number of ways to send email via X++, here are two of the main ones:

 

SysMailer mailer = new SysMailer();

SysEmailParameters parameters = SysEmailParameters::find();

;

if (parameters.SMTPRelayServerName)

{

mailer.SMTPRelayServer(parameters.SMTPRelayServerName,

parameters.SMTPPortNumber,

parameters.SMTPUserName,

SysEmailParameters::password(),

parameters.NTLM);

}

else

{

mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,

parameters.SMTPPortNumber,

parameters.SMTPUserName,

SysEmailParameters::password(),

parameters.NTLM);

}

 

mailer.fromAddress("someoneElse@gmail.com");

mailer.tos().appendAddress("someone@gmail.com");

mailer.body("Hallo");

mailer.sendMail();

 

We have also tried System.Net.Mail:

System.Net.Mail.MailMessage mailMessage;

System.Net.Mail.SmtpClient smtpClient;

System.Net.Mail.MailAddress mailFrom;

System.Net.Mail.MailAddress mailTo;

str smtpServer;

;

mailFrom = new System.Net.Mail.MailAddress('sender@contoso.com',"Sender name");

mailTo = new System.Net.Mail.MailAddress('recipient@contoso.com',"Recipient name");

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

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

mailmessage.set_Subject('This is email subject');

mailmessage.set_Body('This is email body');

 

smtpClient = new System.Net.Mail.SmtpClient(smtpServer);

smtpClient.Send(mailmessage);

mailMessage.Dispose();


 

*This post is locked for comments

I have the same question (0)
  • Sasha Nazarov Profile Picture
    901 on at

    Hi Tina

    Consider adding a try/catch for CLR-exception type, this might reveal what happens with your email.

    Also, there may be some firewall rules in your domain that don't allow for external SMTP relay.

    Finally, I heard Gmail would require some confirmation procedure that would make sending from a particular PC allowed. I am not sure about details, though.

  • PA-22040759-0 Profile Picture
    6,194 on at

    I know this is not an answer to your question, but I just want to point you to an alternative service: www.agermark.com/.../send-mail-with-smtp-through-cloud.html.

    This service is free for up to 200 mails per day.

    At least you could try it out as a way of testing if your firewall accepts SMTP relay.

  • Suggested answer
    Jonathan  Halland Profile Picture
    11,310 on at

    Hi.

    We also had this requirement, but after looking at the internal support in AX, we decided to make use of a third party component to connect to SMTP servers that require intensive attachments or alternative authentication methods. LimiLabs mail.dll client is very good, but I'm sure there are others out there too.

  • Suggested answer
    dolee Profile Picture
    11,279 on at

    I had to use hMailServer (open source) as a middle man between AX and Gmail.

    You can try it out here (https://www.hmailserver.com/)

  • Suggested answer
    Community Member Profile Picture
    on at
    The following code can be used to send an email using SMTP using those services.  The str receiverMailAddress should be a string of email addresses separated by semi-colons(;).


    public void new(str mailSubject, str mailBody, str receiverMailAddress, str _attachment) { List toList; List ccList; ListEnumerator le; System.Net.Mail.AttachmentCollection mailAttachementCollection; System.Net.Mail.Attachment mailAttachment; System.Net.Mail.MailMessage mailMessage; System.Net.Mail.SmtpClient myMail; System.Net.Mail.MailAddressCollection mailToCollection; System.Net.Mail.MailAddress mailFrom; System.Net.Mail.MailAddress mailTo; System.Net.Mail.MailAddress mailCC; str smtpServer; str CcMailAddress; int SMTPPort; #File str mail; userinfo userInfo; str pwd; SysEmailParameters parameters = SysEmailParameters::find(); ; new InteropPermission(InteropKind::ClrInterop).assert(); mailFrom = new System.Net.Mail.MailAddress(parameters.SMTPUserName ,"Name"); toList = strSplit(receiverMailAddress, ';'); le = toList.getEnumerator(); le.moveNext(); mailTo = new System.Net.Mail.MailAddress(strLTrim(strRTrim(le.current()))); try { smtpServer = SysEmaiLParameters::find(false).SMTPRelayServerName;// using the SMTP server ip //setup in email Parameters mailMessage = new System.Net.Mail.MailMessage(mailFrom,mailTo); mailmessage.set_Subject(mailSubject); mailmessage.set_Body(mailBody); mailToCollection = mailMessage.get_To(); while (le.moveNext()) { mailToCollection.Add(strLTrim(strRTrim(le.current()))); } if (_attachment != "") { mailAttachementCollection = mailMessage.get_Attachments(); mailAttachment = new System.Net.Mail.Attachment(_attachment); mailAttachementCollection.Add(mailAttachment); } SMTPPort = SysEmaiLParameters::find(false).SMTPPortNumber; myMail = new System.Net.Mail.SmtpClient(smtpServer, SMTPPort); myMail.set_EnableSsl(true); pwd = SysEmaiLParameters::password(); mymail.set_Credentials(New System.Net.NetworkCredential(parameters.SMTPUserName, pwd)); mymail.Send(mailmessage); } catch(Exception::CLRError) { throw Exception::CLRError; } mailMessage.Dispose(); CodeAccessPermission::revertAssert(); }

  • Vinod321 Profile Picture
    15 on at

    Hi Tina,

    did you get resolved this query. if you resolved it. so please let me know. I also want to do the same task but unable to do that.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans