我需要检查邮件是否发送给现有收件人
这是我的代码
try
{
var smtpServer = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new System.Net.NetworkCredential(MAIL_FROM, PASSWORD),
EnableSsl = true
};
var mail = new MailMessage();
mail.From = MAIL_FROM
mail.To.Add(new MailAddress("nonexisting@gmail.com"));
mail.Subject = title;
mail.Body = content;
smtpServer.Send(mailMessage);
}
catch (SmtpFailedRecipientsException ex)
{
// never occures
}
但是没有接收者时不会发生 SmtpFailedRecipientsException
有没有办法配置 SmtpServer 来触发这个异常?