每次使用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
}