Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

smtpclient " failure sending mail"

here is my code

for(int i = 0; i < number ; i++)
{
    MailAddress to = new MailAddress(iMail.to);
    MailAddress from = new MailAddress(iMail.from, iMail.displayName);
    string body = iMail.body;
    string subject = iMail.sub;
    oMail = new MailMessage(from, to);
    oMail.Subject = subject;
    oMail.Body = body;
    oMail.IsBodyHtml = true;
    oMail.Priority = MailPriority.Normal;
    oMail.Sender = from;
    s = new SmtpClient(smtpServer);
    if (s != null)
    {
        s.Send(oMail);
    }
    oMail.Dispose();
    s = null;
}

this loops sends over 60,000 email. but my problem i am getting " failure sending mail" in some of the email some times 5000 and some time less then that rest of them gets delivered. and i have check all those error out email has valid email address. dont know what is the problem. i really need help in this.

Edit: This is my exception Trace

Error - Failure sending mail.; Inner Ex - System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, 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)

like image 803
Nnp Avatar asked Feb 05 '10 19:02

Nnp


People also ask

Why do emails fail to send?

Generally the Failure sending email error comes when debugged leads to the following error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5. 1 Authentication Required in ASP.Net Application.

Why is SMTP not sending emails?

Check whether there is network access from CSO to the SMTP server. Check whether the firewall is blocking SMTP traffic to SMTP server or whether the ports are blocked. If the server settings and authentication settings are correct, check whether the firewall is blocking port 587 and 465 and SMTP traffic.


1 Answers

Well, the "failure sending e-mail" should hopefully have a bit more detail. But there are a few things that could cause this.

  1. Restrictions on the "From" address. If you are using different from addresses, some could be blocked by your SMTP service from being able to send.
  2. Flood prevention on your SMTP service could be stopping the e-mails from going out.

Regardless if it is one of these or another error, you will want to look at the exception and inner exception to get a bit more detail.

like image 127
Mitchel Sellers Avatar answered Oct 20 '22 04:10

Mitchel Sellers