我正在尝试使用C#发送电子邮件(SMTP),但是“发送电子邮件失败”例外。
我在代码中启用了ssl,并使用465端口(打开的端口)通过system.net.mail库将电子邮件发送到yahoo(smtp.mail.yahoo.com)。
try
{
string mass = " Hi this is compo team email to you for a verification code! your ver fication code is :''" + result + "'' you can enter this code to your compex for go ahead !!!";
string frommail = "<my mail is here>";
string tomail = emailtxt.Text;
string submail = "verification";
string smtptext = "smtp.mail.yahoo.com";
string passmail = "<my email password here> ";
MailMessage mail = new MailMessage(frommail, tomail, submail, mass);
SmtpClient client = new SmtpClient(smtptext);
client.Port = 465;
client.Credentials = new System.Net.NetworkCredential(frommail, passmail);
client.EnableSsl = true;
client.Send(mail);
MessageBox.Show("email sent", "log", MessageBoxButtons.OK);
/////email
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
我该如何解决?怎么了?
打开cmd并运行telnet smtp.mail.yahoo.com 465
有了答案,您将能够找到防火墙和安全性问题还是其他问题。