我正在尝试使用C#发送电子邮件(SMTP),但是有一个例外,“发送电子邮件失败”。
我在代码中启用了SSL,并使用465端口(已打开)通过system.net.mail库将电子邮件发送到Yahoo(smtp.mail.yahoo.com)。
try
{
string mass = " Hi,this is a compo team email to you for a verification code! Your verification 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);
}
我该如何解决?怎么了?