F
Fabio Visin
Hi! I'm studing SmtpFailedRecipientException 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("(e-mail address removed)");
MailAddress to = new MailAddress("(e-mail address removed)");
MailMessage message = new MailMessage(from, 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("smtp.xxx.it");
// Include credentials if the server requires them.
client.Credentials =
(ICredentialsByHost)CredentialCache.DefaultNetworkCredentials;
Console.WriteLine("Sending an e-mail message to {0} using the SMTP host
{1}.", to.Address, client.Host);
try
{
client.Send(message);
}
catch (SmtpFailedRecipientException ex) {
Console.WriteLine("Failed to deliver message to {0}",
ex.FailedRecipient);
//send e-mail back
MailMessage messageError = new MailMessage(from, from);
messageError.Subject = "Error - " + message.Subject;
messageError.Body = ex.Message;
client.Send(messageError);
}
}
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 SmtpFailedRecipientException 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
e-mail.
I modified a sample code founded on MSDN so:
public static void errorMail()
{
MailAddress from = new MailAddress("(e-mail address removed)");
MailAddress to = new MailAddress("(e-mail address removed)");
MailMessage message = new MailMessage(from, 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("smtp.xxx.it");
// Include credentials if the server requires them.
client.Credentials =
(ICredentialsByHost)CredentialCache.DefaultNetworkCredentials;
Console.WriteLine("Sending an e-mail message to {0} using the SMTP host
{1}.", to.Address, client.Host);
try
{
client.Send(message);
}
catch (SmtpFailedRecipientException ex) {
Console.WriteLine("Failed to deliver message to {0}",
ex.FailedRecipient);
//send e-mail back
MailMessage messageError = new MailMessage(from, from);
messageError.Subject = "Error - " + message.Subject;
messageError.Body = ex.Message;
client.Send(messageError);
}
}
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 SmtpFailedRecipientException 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