Dailycode.info

Short solution for short problems

Service not available, closing transmission channel. The server response was: 4.3.2 Service not available, closing transmission channel

Trying to look up this error only gave 2 results and did not provide the simple solution for this problem I found.

Thsi code worked fine before we changed to a secure Exchange 2007 server.

MailBody.Insert(0, "Dear, <br><br>");
 
            string[] mails = toString.Split(';');
  
            MailAddress from = new MailAddress(sharepoint@dailycode.net);
 
            MailMessage Message = new MailMessage();
 
            foreach (string mailAdress in mails)
            {
                Message.To.Add(mailAdress);
            }
            Message.From = from;
            Message.Subject = "Document needs revising!";
            Message.Body = MailBody.ToString();
            Message.IsBodyHtml = true;
             
            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Host = System.Configuration.ConfigurationSettings.AppSettings["SmtpServer"];
            smtpClient.Send(Message);

Then we changed and I got the beautifull error message: "Service not available, closing transmission channel. The server response was: 4.3.2 Service not available, closing transmission channel". So what did the trick was adding:

            smtpClient.UseDefaultCredentials = true;


You can also pass credentials if the program will run under a local user.  This can be done like this:

      smtpClient.Credentials = GetMailCredentials();
 
private static System.Net.NetworkCredential GetMailCredentials()
        {
            System.Net.NetworkCredential cred = new System.Net.NetworkCredential();
            cred.UserName = ConfigurationSettings.AppSettings["User"];
            cred.Password = ConfigurationSettings.AppSettings["Pwd"];
            cred.Domain = ConfigurationSettings.AppSettings["Dom"];
            return cred;
        }

Reading this makes it seem very logic, secure server disables anonymous login.