C# .NET - Error sending mail - Asked By abinav shankar on 17-Jan-12 04:40 AM

hi
 
I use the code below to send mail using yahoo smtp and ended up with error failed sending mail pl check the code and tell me where I went wrong
public void sendMail()
  {
    SmtpClient client = new SmtpClient();
    MailMessage message = new MailMessage();
    client.Port = 465;
    //client.Host = "smtp.gmail.com";
    client.Host = "plus.smtp.mail.yahoo.com";//"smtp.bizmail.yahoo.com";
    client.UseDefaultCredentials = true;
    client.Credentials = new System.Net.NetworkCredential("abinav@yahoo.com", "MyPassword");
    client.EnableSsl = true;
    try
    {
      MailAddress SendTo = new MailAddress("mahesh@yahoo.com");
       // MailAddress SendTo = new MailAddress("abinav@yahoo.com");
      MailAddress SendFrom = new MailAddress("abinav@yahoo.com");
      message = new MailMessage(SendFrom, SendTo);
      message.Body = "Test Mail";
      message.Subject = "Test Mail";
      client.Send(message);
    }
    catch (Exception ex)
    {
    }
  }

and I get the error Failure Sending mail
 
and the inner exception states "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host." It works well with smtp.gmail.com but not with yahoo pl help me its very urgent
smr replied to abinav shankar on 17-Jan-12 04:47 AM
I think you doest have permissions to access yahoo.It might be blocked by your network manager.
D Company replied to abinav shankar on 17-Jan-12 04:53 AM
Hello

try this out
in the catch block this might be an exception


    SocketError errorCode; 
   
int nBytesRec = socket.EndReceive(ar, out errorCode); 
   
if (errorCode != SocketError.Success) 
   
{ 
        nBytesRec
= 0; 
   
} 


tell us if it is not worked

Regards
D
Suchit shah replied to abinav shankar on 17-Jan-12 05:01 AM
Did you use IIS SMTP service (http://www.systemnetmail.com/default.aspx) to send email in your project? If so, please make sure that you configure your server correctly and please make sure that Firewall doesn't block the server port you used.

Make sure Firewall or Any antivirus does not block it to send the mail
Sri K replied to abinav shankar on 17-Jan-12 06:34 AM
Hi,

Just Chk UR Firewall or any Antivirus is Blocking Your communcation

OR

connect the servcie 
provider