System.Net.Mail.SmtpException: Service not available, closing transmission channel. The server response was: 4.4.2

25,177

Solution 1

Disposing the smtpclient (objCompose) did the trick.

    // Summary:
    //     Sends a QUIT message to the SMTP server, gracefully ends the TCP connection,
    //     and releases all resources used by the current instance of the System.Net.Mail.SmtpClient
    //     class.
    public void Dispose();

Solution 2

I like wrapping it in a using block. That'll force the dispose and it's very elegant.

using(SmtpClient objCompose = new SmtpClient("xxxx"))
{
    objCompose.Send(mailmessage); 
}
Share:
25,177
rockin'
Author by

rockin'

Updated on February 16, 2020

Comments

  • rockin'
    rockin' over 4 years

    I get this error when I'm frequently sending some e-mail to a list of users. Say it sends 10 mails and 1 gives an error, then sends a couple more mails and gives the same error.

    The code looks like this:

    public static bool SendEmail(string toMail, string fromname, string from, string subject, string body, string BCC)
        {
    
            MailMessage mailmessage = new MailMessage("[email protected]", toMail, subject, body);
            mailmessage.IsBodyHtml = true;
            mailmessage.BodyEncoding = Encoding.GetEncoding(1254);
            mailmessage.SubjectEncoding = Encoding.GetEncoding(1254);
    
            SmtpClient objCompose = new SmtpClient("xxxx");
    
            try
            {
                objCompose.Send(mailmessage); 
    
                return true;
            }
            catch (Exception ex) { 
    
            }
    
            return false;
        }
    

    And the error I get is this:

    System.Net.Mail.SmtpException: Service not available, closing transmission channel. The server response was: 4.4.2 mailer.mailer.com Error: timeout exceeded at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message)

    can anyone please help, this bug is killing me.

    Thanks in advance.

  • garik
    garik about 12 years
    MailMessage.Dispose() (.NET 3.5)
  • Ian Warburton
    Ian Warburton over 11 years
    Didn't work for me. Well... it got rid of the exception but now it just hangs when one sends an email or two.
  • nsimeonov
    nsimeonov over 9 years
    This code compiles just fine under VS 2013, .NET 4.5