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