2012-02-14 18 views
6

मुझे यह त्रुटि तब मिलती है जब मैं अक्सर उपयोगकर्ताओं की सूची में कुछ ई-मेल भेज रहा हूं। मान लें कि यह 10 मेल भेजता है और 1 त्रुटि देता है, फिर कुछ और मेल भेजता है और एक ही त्रुटि देता है।System.Net.Mail.SmtpException: सेवा उपलब्ध नहीं है, ट्रांसमिशन चैनल बंद कर रहा है। सर्वर प्रतिक्रिया थी: 4.4.2

कोड इस तरह दिखता है:

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; 
    } 

और त्रुटि मैं यह है:

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)

किसी को भी कृपया मदद कर सकते हैं, इस बग मुझे मार रहा है।

अग्रिम धन्यवाद।

उत्तर

8

smtpclient (objCompose) का निपटान चाल चल रहा था।

// 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(); 
+0

MailMessage.Dispose() (.NET 3.5) – garik

+3

मेरे लिए काम नहीं किया। खैर ... यह अपवाद से छुटकारा पा लिया लेकिन अब जब कोई ईमेल या दो भेजता है तो यह लटकता है। –

4

मुझे इसे एक प्रयोग ब्लॉक में लपेटना पसंद है। यह निपटान को मजबूर करेगा और यह बहुत ही सुरुचिपूर्ण है।

using(SmtpClient objCompose = new SmtpClient("xxxx")) 
{ 
    objCompose.Send(mailmessage); 
} 
+1

त्रुटि: अंतर्निहित रूप से प्रकार SmtpClient को IDisposal –

+0

में परिवर्तित नहीं कर सकता है यह कोड VS 2013, .NET 4.5 के ठीक ठीक है – nsimeonov

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^