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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Sending email from D365 FO SMTP

(0) ShareShare
ReportReport
Posted on by

Hi experts

I wants to trigger email from d365FO and I have done below configuration:

After setting email parameter, I have validated - test email was successful on email parameter but when I tried to trigger email using code it's throwing below error: 

pastedimage1663592318685v1.png

Error while trigger using X++ code:

pastedimage1663592641831v2.png

Code:

class TestEmail
{
    public static void main(Args  _args)
 
    {
        SysEmailParameters _SysEmailParameters;
       
        var builder = new SysMailerMessageBuilder();
 
        select SMTPUserName from _SysEmailParameters;
       
        builder.setFrom(_SysEmailParameters.SMTPUserName);  <-- error on this line; this line of code expecting email id but actual value is userId
 
        builder.addTo("TestEmail@TestDomain.com");
 
        builder.setSubject("For D365 email for Learning Purpose");
 
        builder.setBody("Hello this is Komal");
 
        var message = builder.getMessage();
 
        SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(message);
 
        Info("Email Sent Successfully");
    }
 
}

I have the same question (0)
  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    You're trying to specify the user name (AHGSX...) as the "from" e-mail address, but it clearly isn't valid e-mail address.

    By the way, please use Insert > Code (in the rich-formatting view) to paste source code.

  • Community Member Profile Picture
    on at

    I have seen some online blog, there they are setting userId in the email parameter.

    Note: When we have set UserId on email parameter, test email was successful on email parameter.

    Pls help.

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    Yes, sending the test email works, because it's implemented correctly. The bug is in your own code.

    The user name is used for authentication, when the SMTP servers requires a username and password. The problem is that you're trying to use it as an e-mail address, which is a completely different thing.

  • Community Member Profile Picture
    on at

    Thanks Martin.

    Debugger is also says the something. debugger shows error on below line of code.

     builder.setFrom(_SysEmailParameters.SMTPUserName);  <-- error on this line; this line of code expecting email id but actual value is userId

    If possible could you please advice what line of code should I wrote ?

  • Suggested answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    The "from" e-mail address should be an e-mail address (such as test@mycompany.com), not just any text. What you're using (AGHSXSXGS...) doesn't have the format of an e-mail address.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 616

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 460 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 331 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans