Hi! I'm studing SmtpFailedRecip ientException to trap errors when I'm sending
e-mail.
I modified a sample code founded on MSDN so:
public static void errorMail()
{
MailAddress from = new MailAddress("fa *********@xxx.i t");
MailAddress to = new MailAddress("we *******@xxx.it" );
MailMessage message = new MailMessage(fro m, to);
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an e-mail message from
an application very easily.";
SmtpClient client = new SmtpClient("smt p.xxx.it");
// Include credentials if the server requires them.
client.Credenti als =
(ICredentialsBy Host)Credential Cache.DefaultNe tworkCredential s;
Console.WriteLi ne("Sending an e-mail message to {0} using the SMTP host
{1}.", to.Address, client.Host);
try
{
client.Send(mes sage);
}
catch (SmtpFailedReci pientException ex) {
Console.WriteLi ne("Failed to deliver message to {0}",
ex.FailedRecipi ent);
//send e-mail back
MailMessage messageError = new MailMessage(fro m, from);
messageError.Su bject = "Error - " + message.Subject ;
messageError.Bo dy = ex.Message;
client.Send(mes sageError);
}
}
I don't understand why it doesn't work well!
If I send an e-mail to a unavailable mailbox inside my smtp client there is
the SmtpFailedRecip ientException and it works fine but if I try to an
external unavailable mailbox I don't receive any exception. Where I make the
mistake? how can I solve it?
thanks
Fabio Visin