1
votes

for sending email i set server name smtp.mail.yahoo.com and port is 465 i trying to send email but failed to send email

what is the correct servername and smtp port to send email using yahoo

what other configuration i needed to set ?

my code is here :

  System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();


                message.To.Add(address);
                message.Subject = subject;
                message.From = new System.Net.Mail.MailAddress(from);
                message.Body = body;
                message.Bcc.Add(bcc);
                message.CC.Add(cc);
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.mail.yahoo.com");
                smtp.Credentials = new System.Net.NetworkCredential(emailid,password);
                smtp.Port = 465;
                smtp.EnableSsl = true;
                smtp.Send(message);
2
Please define "failed to send email", what happened? did it throw an exception if so what was the error message?Ben Robinson
exception error failure to send mailAshwin

2 Answers

6
votes

I just tried the code and I think the yahoo mail server does not use SSL, because if you comment out

 //smtp.Port = 465;
 //smtp.EnableSsl = true;

it works.

1
votes

I am not confirm about your smtp server settings these are working fine for me.. replace your smtp server settings and have idea from this code snippet.

some of the smtp server standart settings are here:

http://www.emailaddressmanager.com/tips/mail-settings.html

//Send mail using Yahoo id protected void Button2_Click(object sender, EventArgs e) { String frmyahoo = "[email protected]"; //Replace your yahoo mail id String frmpwd = "fromidpwd"; //Replace your yahoo mail pwd String toId = txtTo.Text; String ccId = txtCc.Text; String bccId = txtBcc.Text; String msgsubject = txtSubject.Text; String mailContent = txtContent.Text;

        try
        {
            MailMessage msg = new MailMessage();

            msg.To.Add(toId);
            MailAddress frmAdd = new MailAddress(frmyahoo);
            msg.From = frmAdd;

            //Check user enter CC address or not
            if (ccId != "")
            {
                msg.CC.Add(ccId);
            }
            //Check user enter BCC address or not
            if (bccId != "")
            {
                msg.Bcc.Add(bccId);
            }
            msg.Subject = msgsubject;
            //Check for attachment is there
            if (FileUpload1.HasFile)
            {
                msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
            }
            msg.IsBodyHtml = true;
            msg.Body = mailContent;

            SmtpClient mailClient = new SmtpClient("smtp.mail.yahoo.com", 25);
            NetworkCredential NetCrd = new NetworkCredential(frmyahoo, frmpwd);
            mailClient.UseDefaultCredentials = false;
            mailClient.Credentials = NetCrd;
            mailClient.EnableSsl = false;
            mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            mailClient.Send(msg);

            clear();
            Label1.Text = "Mail Sent Successfully";
        }
        catch (Exception ex)
        {
            Label1.Text = "Unable to send Mail Please try again later";
        }
    }