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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Sending email error using SysMailerFactory object

(2) ShareShare
ReportReport
Posted on by 242
Hello all,
We have an on-premise client when we try to send an email using SysMailerFactory object we got an error requesting authentication using SMTP.
When investigating we found that client uses relay outgoing email server which allows annonymous email senders without restrication,
but when using SysMailerFactory we got the following error:
did we miss something, please?
Here is the full code:
 public static void sendEmailWithCC(str templateId, str emailTo, str emailCC, Map templateToken)
 {
     Email   emailFrom, subjectTxt;
     str     emailFromName, emailBody;
     var mailer          = SysMailerFactory::getNonInteractiveMailer();
     var messageBuilder  = new SysMailerMessageBuilder();

     [subjectTxt, emailBody, emailFrom, emailFromName] =
             SendEmailHelper::getEmailTemplate(templateId);

     if (emailTo != '')
     {
         System.Exception e;
         try
         {
             messageBuilder.reset()
              .addTo(emailTo)
              .addCc(emailCC)
              .setSubject(subjectTxt)
              .setBody(SysEmailMessage::stringExpand(
                 emailBody, SysEmailTable::htmlEncodeParameters(templateToken)))
                 .setFrom(emailFrom);
             //messageBuilder.addCc(emailCC);
             mailer.sendNonInteractive(messageBuilder.getMessage());
         }
         catch(e)
         {
             checkFailed(strFmt("%1", e.ToString()));
         }
     }

 }
Note that workflow notification emails are sent normally without any issues.
I have the same question (0)
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
     
    It seems to me that the settings are not correct. Can you debug it to make sure that it is retrieving the SMTP connection informations correctly ?
     
    Best regards,
    Mohamed Amine MAHMOUDI
  • MS-29011540-0 Profile Picture
    242 on at
    @Mohamed Amine Mahmoudi
    Thanks for your reply,
    The configuration in the email parameters doesn't have require authentication option, and they depend on a relay smtp server to send emails which allow anonymous senders and uses port 25.
    workflow and system notification emails are sent successfully, meanwhile SysMailerFactory can't be sent giving the above error attached in the post.
    After searching i will try to use the same technique workflows emails are sent (using SysEmailTable):

    SysEmailTable::sendMail(sysEmailTable.EmailId,
                               'en-us', // Chosen language
                               'WhoYouSendThisTo@fakemail.com', // Who you're sending the email to
                               mappings, // Your variable mappings
                               'd:\\a.pdf' // Location of file attachment (server/client matters) or none
                               '' , // XML if you're using XSLT
                               true, // Traceable or not?
                               'admin', // Sending user
                               true); // Use retries?
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,390 Super User 2025 Season 2 on at
     
    I think you must ensure that the email settings are correct and working.
    then in user options the sender email have the same email in email parameters.
     
    Best regards,
    Mohamed Amine

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 687 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 535 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 403 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans