SmtpFailedRecipientException/s - how it works?

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
 
S

Steven Cheng[MSFT]

Hi Fabio,

From your description, you're using the .NET 2.0 SmtpClient class to send
email and found that you'll get exception if you send mail to an invalid
address in local network, but didn't get any error when send to an external
invalid address ,correct?

As for this problem, I think the error you got when sending to local
invalid recipient is due to the SMTP server's validation. Are you sending
through a network SMTP server(such as Exchange server)? The SMTP server in
local environent may valid the recipient address immediately(if it is a
local address) and raise error if it is invalid. For external email
address, since the SMTP request will be foward to external intermediate
node, the local SMTP server may not validate it at the exact time,
therefore, your SMTP client does not receive such error information.
Actually, for those mail client such as outlook, when sending it the mail
,it will not validate external mail address immediately. It is later after
the external node send back error message will it popup message sending
fail error. The SmtpClient component will close the communcation with
server right after the message has been sent out, but not trace the
sequentital message delivery status.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
F

Fabio Visin

Hi Steven,
thanks for the reply, your analysis is completely correct.
Reading your explanation I don't understand the real use of this exception
if I can't get the correct information. Is there the possibility, with a
different approach too, to trace the sequential message delivery status?
I have to check the validity of many e-mail address stored in my DB but I
can't do it manually, there are too much! ;)

Thanks
Fabio
 
S

Steven Cheng[MSFT]

Hi Fabio,

After some further research, I found that this should be done through the
smtp server's setting. For example, if your local smtp server is a network
exchange server, the exchange server contains storage for each local
users(on the server) and there you can query the failture messages for each
given user. For other smtp server, it may have different setting or
interface.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top