I need to check if mail was send to existing recipient
Here is my code
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("[email protected]"));
mail.Subject = title;
mail.Body = content;
smtpServer.Send(mailMessage);
}
catch (SmtpFailedRecipientsException ex)
{
// never occures
}
But SmtpFailedRecipientsException never occures when there is no recipient
Is there a way to configure SmtpServer to fire this exception?
The problem is that GMail doesn't say that the user is invalid during the SMTP transaction. The reason is that spammers used to perform dictionary attacks looking for "[email protected]" and "[email protected]", etc. Any address that didn't get marked as "not there" would then be a valid address. So most SMTP servers now just accept all addresses during the SMTP transaction and either just silently drop the invalid ones or send a bounce message later. In either case there's no way in code to determine this.