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"

Applies to: Microsoft Dynamics AX 4.0

Symptoms


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 e-mail message is not sent. Additionally, you receive the following error message:
Method 'send' in COM object of class 'CDO.Message' returned error code 0x80040213 (<unknown>) which means: The transport failed to connect to the server.

Cause


This issue may occur if the following conditions are true:
  • The local SMTP server is on a computer that is running Microsoft Windows Server 2003.
  • The Internet Protocol (IP) address of the SMTP virtual server is set to the IP address of the local computer.

Resolution


To resolve this issue, change the IP address of the SMTP virtual server to use the All Unassigned option, and then run the code to programmatically send the e-mail message.

To change the IP address of the SMTP virtual server, follow these steps:
  1. Click Start, point to All Programs, point to Administrative Tools, and then click Internet Information Services (IIS) Manager.
  2. Expand the Microsoft Dynamics AX 4.0 server.
  3. Right-click Default SMTP Virtual Server, and then click Properties.
  4. On the General tab, click (All Unassigned) in the IP address box.
  5. Click OK to close the Default SMTP Virtual Server Properties dialog box.

More Information


Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

The following code is an example of how to programmatically send an e-mail message by using the Send method in Microsoft Dynamics AX 4.0.
static void SysMailer(Args _args)
{
SysMailer mailer;
;

mailer = new SysMailer();
mailer.body("This is the body of the mail");
mailer.subject("The message subject");
mailer.fromAddress("alias@domain");
mailer.tos().appendAddress("alias@domain");
mailer.SMTPRelayServer("domain_name_of_SMTP_Server");

mailer.sendMail();

pause;
}
If you are using the Alert functionality to be notified either by pop-up messages or by e-mail messages, you may need to verify that the settings are correct in Internet Information Services (IIS) Manager. To do this, follow these steps:
  1. In IIS Manager, expand the Microsoft Dynamics AX 4.0 server.
  2. Right-click Default SMTP Virtual Server. Then, click Properties.
  3. Click the Access tab.
  4. Click Connections.
  5. Verify that the “All except the list below” option is selected. Or, if the “Only the list below” option is selected, verify that the list is not empty.
  6. In Connection window, click OK to accept the change.
  7. Click Relay. Then, repeat steps 5 through 6.
  8. Verify that the All except the list below option is selected. Or, if the “Only the list below” option is selected, verify that the list is not empty.