0
我想用c#发送电子邮件以下是我的代码。发送电子邮件时出错
try
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress("[email protected]");
msg.To.Add("[email protected]");//Text Box for To Address
msg.Subject = "Testinng subject"; //Text Box for subject
msg.IsBodyHtml = true;
msg.Body = "testing comment is here..";//Text Box for body
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("[email protected]", "");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
object userstate = msg;
client.Send(msg);
}
catch (Exception ex)
{
throw ex;
}
捐赠以下异常
如果您只是要再次抛出异常,捕捉异常毫无意义。 – Bernard 2012-03-27 17:48:20
确保端口没有被防火墙阻挡 – 2012-03-27 17:48:43
@Erno我已经关闭了防火墙。 – 2012-03-27 17:50:00