Sending email with invalid address

G

Guest

Hi folks,

I am using the Send method in the System.Web.Mail.SmtpMail class.

If I pass an address that does not exist or is in anyway invalid, I throw and
exception as shown below. I need to determine how I can check to see
if the email address is invalid before I call the Send method which does not
return a value. - thanks, - Glenn

Server Error in '/' Application.
--------------------------------------------------------------------------------

The server rejected one or more recipient addresses. The server response
was: 550 5.1.1 <[email protected]> User unknown; rejecting
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The server
rejected one or more recipient addresses. The server response was: 550 5.1.1
<[email protected]> User unknown; rejecting

Source Error:


Line 185:
Line 186: System.Web.Mail.SmtpMail.SmtpServer = "mail.yazo.com"
Line 187: System.Web.Mail.SmtpMail.Send(mailMessage)
Line 188: End Sub
Line 189:
 
T

Tim_Mac

usually the mail will be relayed to another mail server and then it will be
rejected back later if it is invalid, you won't get any exception because
your code won't wait for the mail servers to communicate with each other.
however in your case the mailbox is on the server you specify so it rejects
the message straight away, and you get the exception.
i think your only option is to add a try and catch block around your code
and then act accordingly if the message fails.
it's a good idea to have this anyway because the connection to the mail
server could be down. there are a host of reasons why the message could fail
and without a try/catch your code will crash in these situations. the mail
component used in .net 1.1 wasn't very good, the 2.0 System.Net.Mail
component is much improved, something to look forward to!

tim
 
G

Guest

Tim,

Thanks for your help on this issue. Regarding 2.0 vs 1.1, I have been a
little hesitant to migrate to 2.0 based on the problems I have heard
when attempting to do so. I plan to move on this soon and I suppose
it is inevitable and I have a good description of the process and the
gotcha's to look out for from online.

So I'll put that try catch block in...

Thanks again,

- Glenn
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top