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)

How to Send an Email from AX?

(0) ShareShare
ReportReport
Posted on by 1,883

Dear Experts,

I did some configuration for email functionality with this Link. In Link there is some steps for AX email functionality and I completed setup up to Configure batch job. Now I have following job to test this settings that my AX Environment sends emails or not. I observe that Email Sending Status for some particular time the Status is Waiting(0) and then turns Failed. Please help me to resolve my issue.

void SentEmail()
{
    SysMailer mail;
    SysOutgoingEmailTable outgoingEmailTable;
    SysEmailItemId nextEmailItemId;
    Map map;
    str SenderName, SenderEmail, To, Subject, Body;
;

SenderName = "X++.info";
SenderEmail = "test1@gmail.com";
To = "test2@gmail.com";
Subject = "Test Email From AX";
Body = "<B>Hi this is AX World. Hope you receive my email</B>";

nextEmailItemId = EventInbox::nextEventId();
outgoingEmailTable.EmailItemId = nextEmailItemId;
outgoingEmailTable.IsSystemEmail = NoYes::No;
outgoingEmailTable.Sender = SenderEmail;
outgoingEmailTable.SenderName = SenderName;
outgoingEmailTable.Recipient = To;
outgoingEmailTable.Subject = SysEmailMessage::stringExpand(Subject, map);
outgoingEmailTable.Priority = eMailPriority::Normal ;
outgoingEmailTable.WithRetries = false;
outgoingEmailTable.RetryNum = 0;
outgoingEmailTable.UserId = curUserId();
outgoingEmailTable.Status = SysEmailStatus::Unsent;
outgoingEmailTable.Message = Body;
outgoingEmailTable.LatestStatusChangeDateTime = DateTimeUtil::getSystemDateTime();
outgoingEmailTable.insert();
}


Best Regards,

Faqru Shaik

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Prashant Singh Profile Picture
    8,802 on at

    Dear Faqru Shaik,

    Please check your outgoing email server setup and email sender name in email template.  Also your smtp server setup. 

    Regards,

    Prashant Kumar

  • Faqruddin Profile Picture
    1,883 on at

    Hi Prashant,

    Thanks for your reply. Please check my screenshots.

    3073.emailtemplate.jpg

    smtp1.jpg

    smtp2.jpg

    3073.emailtemplate.jpg

    email.jpg

  • Suggested answer
    Prashant Singh Profile Picture
    8,802 on at

    Dear Faqru Shaik,

    Please try to select anonymous access check in authentication form. I had similar issue it helped me to send email. Also restart the SMTP server.

  • Faqruddin Profile Picture
    1,883 on at

    Hi,

    As you said I select anonymous access in authentication form. Still the same issue exists.

    Thanks

    Faqru Shaik

  • Community Member Profile Picture
    on at

    Hello Faqru Shaik, few months back i wrote a blog on "SMTP server and email configuration". You can follow. It may help you.

    gautamax.blogspot.in/.../e-mail-configuration-in-ax-2012.html

  • Faqruddin Profile Picture
    1,883 on at

    Hello Gautam,


    Thanks for your reply. I already done all that steps from Microsoft blog. I have here two issues. When I'm running the following job info is giving message "Email has been sent" but I didn't receive the test email from AX and I check all my email folders. Coming to second job I check System Administrator->Email Sending Status is Waiting(0) and then turns failed after sometime. Please check my below two jobs

    JOB 1: O/P :   Email has been sent but didn't receive the test email from AX.

    static void SendEmail(Args _args)
    {
        SysEmailParameters parameters = SysEmailParameters::find();
        SMTPRelayServerName relayServer;
        SMTPPortNumber portNumber;
        SMTPUserName userName;
        SMTPPassword password;
        Str1260 subject,body;
        InteropPermission interopPermission;
        SysMailer mailer;
        System.Exception e;
    
        ;
        if (parameters.SMTPRelayServerName)
            relayServer = parameters.SMTPRelayServerName;
        else
            relayServer = parameters.SMTPServerIPAddress;
            portNumber = parameters.SMTPPortNumber;
            userName = parameters.SMTPUserName;
            password = SysEmailParameters::password();
            subject = "Test Email from AX";
            body = "<B>Test Email from AX</B>";
    
            CodeAccessPermission::revertAssert();
    
            try
            {
                interopPermission = new InteropPermission(InteropKind::ComInterop);
                interopPermission.assert();
                mailer = new SysMailer();
                mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
                //instantiate email
                mailer.fromAddress("user1@domain.com");
                mailer.tos().appendAddress("user2@domain.com");
                mailer.subject(subject);
                mailer.htmlBody(body);
                mailer.sendMail();
                CodeAccessPermission::revertAssert();
                info("Email has been send!");
                }
                catch (Exception::CLRError)
    
                {
                    e = ClrInterop::getLastException();
    
                while (e)
    
                {
                    info(e.get_Message());
    
                    e = e.get_InnerException();
                }
    
                CodeAccessPermission::revertAssert();
                //info(e);
                info ("Failed to Send Email some Error occure");
        }
    
    }

    JOB2: O/P: Email Sending Status is Waiting(0) then turns to failed after sometime.

    void TestEmail()
    {
        SysMailer mail;
        SysOutgoingEmailTable outgoingEmailTable;
        SysEmailItemId nextEmailItemId;
        Map map;
        str SenderName, SenderEmail, To, Subject, Body;
    ;

    SenderName = "Faqru Shaik";
    SenderEmail = "user1@domain.com";
    To = "user2@domain.com";
    Subject = "Test Email From AX";
    Body = "<B>Hi this is AX World. Hope you receive my email</B>";

    nextEmailItemId = EventInbox::nextEventId();
    outgoingEmailTable.EmailItemId = nextEmailItemId;
    outgoingEmailTable.IsSystemEmail = NoYes::No;
    outgoingEmailTable.Sender = SenderEmail;
    outgoingEmailTable.SenderName = SenderName;
    outgoingEmailTable.Recipient = To;
    outgoingEmailTable.Subject = SysEmailMessage::stringExpand(Subject, map);
    outgoingEmailTable.Priority = eMailPriority::Normal ;
    outgoingEmailTable.WithRetries = false;
    outgoingEmailTable.RetryNum = 0;
    outgoingEmailTable.UserId = curUserId();
    outgoingEmailTable.Status = SysEmailStatus::Unsent;
    outgoingEmailTable.Message = Body;
    outgoingEmailTable.LatestStatusChangeDateTime = DateTimeUtil::getSystemDateTime();
    outgoingEmailTable.insert();
    }

  • Community Member Profile Picture
    on at

    Are you using the same domain for email address which you have configured. For example if you're using Gmail domain than you need to specify gmail SMTP Port which is : 587 or you can find in google.

  • Faqruddin Profile Picture
    1,883 on at

    Yes I'm using gmail domain with port 587. But the issue is same.

  • Verified answer
    Faqruddin Profile Picture
    1,883 on at

    Thanks for your prompt replies. Please use below link, Clearly explained SMTP configuration for office 365 and gmail. I resolved my issue.

    www.uxceclipse.com/.../fact-sheet-dynamics-ax-2012-configuring-alerts-and-emails.pdf

    Thanks

    Faqru Shaik

  • Tpee Profile Picture
    120 on at

    Hi Faqru Shaik,

    May you kindly drop the link to the pdf. again please.

    When I click this link: www.uxceclipse.com/.../fact-sheet-dynamics-ax-2012-configuring-alerts-and-emails.pdf

    It does not take me to the configuration steps.

    Thanking you in advance for your assistance.

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