Click here to Skip to main content
14,392,354 members
Rate this:
Please Sign up or sign in to vote.
See more:
hello
How Do I Implement Error Handling when Sending Email with ASP.NET.
Thank you in advance
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Taken that you use C# you put the code sending the email inside a try..catch block.

See How to: Use the Try/Catch Block to Catch Exceptions[^]
   
Comments
user12213212 22-Jul-15 3:15am
   
that s right.but which exception occure?i want this.
Wendelius 22-Jul-15 3:40am
   
You can have separate catch block for different exceptions if you like. However, different errors don't always generate different kinds of exceptions. Because of this it's important to investigate the exception properties such as message. Have a look at https://msdn.microsoft.com/en-us/library/system.exception(v=vs.110).aspx[^]
Rate this:
Please Sign up or sign in to vote.

Solution 2

You can use try catch block to handle exception in email code block.

try
{
//code to send email
}
catch (SmtpException ex)
{
    //log exception or throw to upper layer as per your requirement
}
catch (Exception ex) //This will handle errors other than thrown feature other than SMTP
{
   //log exception or throw to upper layer as per your requirement
}
   
Comments
user12213212 22-Jul-15 3:14am
   
thanks,but i want list of exception and create Appropriate message.for example recipient is not valid and other.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100