每次我使用 SmtpClient 发送电子邮件时,我总是收到电子邮件?完全看不出为什么?请帮忙谢谢。
从我的控制器:
foreach(var reciever in notifications.ToList() ) {
var msg = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress("notifications@someone.com");
mail.Subject = subject;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = body; // contains html email
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
//Add the Creddentials- use your own email id and password
client.Credentials = new System.Net.NetworkCredential(MyConfig.SmtpLogin, MyConfig.SmtpPassword);
client.Port = PlayCaddyMailerConfig.SmtpPort; // 587; // Gmail works on this port
client.Host = PlayCaddyMailerConfig.SmtpServer; // "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
try
{
client.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
throw ex2;
} // end try
}