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 :
Microsoft Dynamics AX (Archived)

Method 'send' in COM object of class 'CDO.Message' returned error code 0x80040213 (<unknown>) which means: The transport failed to connect to the server.

(0) ShareShare
ReportReport
Posted on by 6

Job below works fine. However same job with parameters set through class does not. Sysmailer.send() issues error 0x80040213. The code below is written in a class does not works and issues said error.

Public class TerminationEmail
{
}

Public server static void SendEmail(str authorityemail, HcmReasonCode hcmReasonCode, HcmWorker hcmWorker)
{
SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
SMTPPassword password;
Str1260 subject,body;
InteropPermission interopPermission;
SysMailer mailer;
System.Exception e;
ReasonCode reasoncode;
Description description;
Name name;
Email email;

#define.terminationemail("Termination Email");
reasoncode = hcmReasonCode.ReasonCodeId;
description = hcmReasonCode.Description;
relayServer = parameters.SMTPServerIPAddress;
portNumber = parameters.SMTPPortNumber;
userName = parameters.SMTPUserName;
password = SysEmailParameters::password();
subject = #terminationemail;
name = hcmWorker.name();
email = HcmWorker.email();
body = 'Dear' + strFmt(name) + ', you have been terminated by' + strFmt(userName)
+ 'for reason' + strFmt(reasoncode) + strFmt(description) + 'We wish you good luck';

CodeAccessPermission::revertAssert();

try
{
interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();
mailer = new SysMailer();
mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
mailer.fromAddress(userName);
mailer.tos().appendAddress(email);
mailer.ccs().appendAddress(authorityemail);
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 ('Failed to Send Email some Error occure');
}
}

This code works fine.

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 = "Subject line for the email";
body = "<B>Body of the email</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("vinodh@cbizol.com");

mailer.tos().appendAddress("vinod.dayalan@gmail.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");
}

}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Your e-mail settings are incorrect. This post is for AX 4.0, but still applies to newer versions:

    support.microsoft.com/.../error-message-when-you-try-to-programmatically-send-an-e-mail-message-to-the-local-smtp-server-by-using-the-send-method-in-microsoft-dynamics-ax-4.0-the-transport-failed-to-connect-to-the-server

    The menu path is different, it is now the E-mail parameters, so check what you've put in the computer name settings for the mail server.

  • Vilmos Kintera Profile Picture
    46,149 on at

    If the answers above have resolved your issue, take your time to tick the checkbox next to the helpful posts to close the topic.

  • NoobDaxCoder Profile Picture
    6 on at

    5635.Capture.JPG

    My Email settings are correct. All parameters are receiving arguments. Tried gmail id with gmail port number too. It is not working. I am not sure what is problem.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    First of all, remove local computer name. Also try an Exchange server on your network instead of free provider, since they might have more strict requirements for settings like SSL/TLS for transport protocol, which is not supported without making changes to your AX application.

    As for the user and password, that is supposed to be a domain account, not an e-mail/password combination.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Also one more thing, here is a nice whitepaper on how to set up your own mail server with relaying enabled, that is capable to communicate with external providers too like Gmail, and user your own mail server for sending AX e-mails:

    www.uxceclipse.com/how-to-configure-dynamics-ax-2012-alerts-emails-using-an-smtp-email-relay-server-with-office-365

  • Vilmos Kintera Profile Picture
    46,149 on at

    Can you please make sure you tick the checkboxes for helpful answers next to each post, so the topic gets resolved? Thank you.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans