BizTalk: SMTP – The transport error code was 0x80040217

The Full Error Was

The message could not be sent to the SMTP server. The transport error code was 0x80040217

Solution

I had to go to the BizTalk Adapters in BizTalk Admin Console, find the SMTP adapter, then configure it for the host.
On the properties window, there is an “Authentication Type” which defaulted to “NTLM Authentication”.

You may need to talk to your infrastructure/email team to see what is required by your email server. You might need to provide a basic authentication userid/password here.

You can optionally specify your email server name here, and default “reply-to email address”, rather having to specify it in every single SMTP Send Port.

Alternatively

C# to Send Email

The C# Mail.sendEmail method below can be called from a BizTalk Orchestration to send an email.
You can also write a wrapper test method to call it. When I got the error above, I checked this C# first, and it was able to send an email, so I knew the issue was in BizTalk.

The routine below is bare-bones as simple as can be. It doesn’t handle authentication or attachments or HTML bodies. So it could be enhanced with more parms to handle those types of scennarios.

Alternatively, you could try turning off or changing the authentication in the Send Port itself, but several other issues and blogs I found suggested that you have to setup the adapter first, before trying any overrides on the Send Port.

<pre>

    public class Mail
    {

        // Example Call: 
          ABC.Helpers.Mail.sendEmail("nrwalters@abc.com", "EmailTester C#", "This is the message body"); 

        //send an email alert
        public static void sendEmail(string recipient, string subject, string message)
        {
            try
            {
                string from = "noreply@abc.com";
                //string host = "smtp.abc.com";
                int smtpPort = 25;

                //append the system name to the email
                string systemEnvironmentName = Config.getConfigValue("systemName");
                subject = subject.Trim() + " [" + systemEnvironmentName.Trim() + "]";

                MailMessage mail = new MailMessage();
                SmtpClient client = new SmtpClient();

                //set the email address from address
                MailAddress fromEmail = new MailAddress(from);
                mail.From = fromEmail;

                //split the recipient email address by ';' and add
                foreach (var address in recipient.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    mail.To.Add(address);
                }

                client.Port = smtpPort;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Host = host;
                mail.Subject = subject;
                mail.Body = message;
                mail.IsBodyHtml = false;

                client.Send(mail);
            }
            catch (SmtpException ex)
            {
                LoggingToFiles.logHelperError("sendEmail", ex.Message);
                throw new Exception("SMTP.Exception in function sendEmail: " + ex.Message);
            }
            catch (Exception ex)
            {
                LoggingToFiles.logHelperError("sendEmail", ex.Message);
                throw new Exception("Exception in function sendEmail: " + ex.Message);
            }
        }

    }

</pre>

Uncategorized  

Leave a Reply