You must Sign In to post a response.
  • Category: ASP.NET

    Error sending mail in asp.net

    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 .
  • #652225
    Change the Host name with below one
    * Incoming mail server (POP3): pop.mail.yahoo.com
    * Outgoing mail server (SMTP): smtp.mail.yahoo.com

  • #652232
    The SMTP server you are using might not open to allow sending the mail,
    as there is nothing wrong in the code and you said that the code is working fine for the Gmail server.


    plus.smtp.mail.yahoo.com


    ping this server and check that this is open and responding.

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #652311
    Shashwath77

    use smtp as smtp.mail.yahoo.com its enough to send email and set enable ssl false. try like below code just placed from and to id below code to test working perfectly.


    protected void Button2_Click(object sender, EventArgs e)
    {
    try
    {
    MailMessage msg = new MailMessage("fromid@yahoo.com", "toid@any.com", "subjectofmail", "mail body");
    msg.Body = "<b>Hello User</b>";
    SmtpClient mailClient = new SmtpClient("smtp.mail.yahoo.com", 25); //Change your smtp name and port number
    NetworkCredential NetCrd = new NetworkCredential("fromid@yahoo.com", "frmidpwd");
    mailClient.UseDefaultCredentials = false;
    mailClient.Credentials = NetCrd;
    mailClient.EnableSsl = false;
    msg.IsBodyHtml = true;
    mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    mailClient.Send(msg);
    }
    catch (Exception ex)
    {
    }
    }

    Regards
    N.Ravindran
    Your Hard work never fails

  • #652347
    [Response removed by Admin. Read forum policies.]
    Regards,
    Naveen


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.