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 From AX

(0) ShareShare
ReportReport
Posted on by 106

Hi All,

I'm trying to send email from AX using codes below:

    SysEmailId sysEmailId = "testEmail";
    str recipientEmail = "abc@mail.com";
    Map mappings;

    ;

    super();

    this.enabled(false);

    mappings = new Map(Types::String, Types::String);
    SysEmailTable::sendMail(
            sysEmailId,
            //'en-us',
            SysEmailTable::find(sysEmailId).DefaultLanguage,
            recipientEmail,
            mappings,
            '',
            '',
            true,
            curUserId(),
            true);


What I have done so far:

1. Setup the SMTP server on Windows Server

2. Setup email parameter in System Administration - Email Parameters

The emails are queued in Email Sending Status, but not being sent out to the recipient.

I also tried to send email using PowerShell

Send-MailMessage -SMTPServer localhost -To test@abc.com -From test@abc.com -Subject "This is a test email" -Body "Hi, this is a test email sent using Gmail as a smart host"

But got this error:


+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

I'm using my office email for the sender which is a Microsoft exchange account. Any idea what went wrong?

Thank you!

Regards,

Raymon

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,025 Super User 2025 Season 2 on at

    I Rayon,

    Did you setup the Email distributor batch task? If so, can you check if the messages in the sending status do get another status after it had tried to send the message? The powershell option is stating you are using a Gmail smart host as SMTP? Please elaborate what exchange settings you have done in Dynamics AX. Try to find events on related servers. Using a powershell script could give other errors. E.g. powershell email sending could be blocked by administrators.

  • raymonmon Profile Picture
    106 on at

    Hi Andre,

    I did not setup the distributor task since I'm sending the email when user clicks on View Bill button.

    I changed the powershell using my office email and got this error in return:

    Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated

    I'm not sure I have configured the SMTP server correctly. Can you give me detailed information?

    Thank you.

  • RaviRaj Profile Picture
    530 on at

    Hi raymonmon ,

    Refer this blog

    dynamicserppros.com/creating-automatic-email-confirmations-from-dynamics-ax

  • Jie G Profile Picture
    on at

    Hi Raymon,

    The error message indicated you were sending email without credential but your Exchang connector does not accept anonymous message. Usually Exchange requires authentication. Also, you have to check if your Exchange allows email relay from AOS. Suggest you to check with your exchange server admin.

    How did you set the email parameters? Did you set the user name and password? Reference: technet.microsoft.com/.../aa834374.aspx  

    Best regards,

    Ada

  • raymonmon Profile Picture
    106 on at

    Hi Ada,

    Where to set the authentication for Exchange and check whether it allows email relay from AOS?

    Set the parameter in system administration -> system -> email parameters

    Used my office mail server for the host and port 25.

    Regards,

    Raymon

  • Jie G Profile Picture
    on at

    Hi Raymon,

    For "Where to set the authentication for Exchange", please check the "Connect Microsoft Dynamics AX to the SMTP mail server" in technet.microsoft.com/.../aa834374.aspx

    If the SMTP server requires authentication, enter a valid username and password.

    Select the Use NTLM check box.

    Please ask the Exchange admin to see whether it allows email relay from AOS.

    Best regards,

    Ada

  • André Arnaud de Calavon Profile Picture
    301,025 Super User 2025 Season 2 on at

    Hi Raymonmon,

    The user click will create a record in the sending status only. The batch job will pick the list with new messages and will do the actual sending of the message. So please enable the email batch as described in the documentation. Ada Ding provided the link.

  • raymonmon Profile Picture
    106 on at

    Hi Andre,

    Yes I just added the email batch job. It's now trying to send the email out but still failed. Do you think it's related to my SMTP setting in windows server?

    Thanks.

  • Jie G Profile Picture
    on at

    Hi Raymon,

    Please try to use the IP of SMTP server instead of "localhost" in your Powershell script to test your SMTP settings.

    Send-MailMessage -SMTPServer IP -To test@abc.com -From test@abc.com -Subject "This is a test email" -Body "Hi, this is a test email sent using Gmail as a smart host"

    Best regards,
    Ada

  • raymonmon Profile Picture
    106 on at

    Hi All,

    I managed to send out email using this tutorial

    hellodax.com/.../send-email-via-x-example-code

    Thanks for all your help.

    I have another question regarding emailing in AX, will it be possible to edit the email before sending it to recipient?

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