Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello
How Do I Implement Error Handling when Sending Email with ASP.NET.
Thank you in advance
Posted

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[^]
 
Share this answer
 
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[^]
You can use try catch block to handle exception in email code block.

C#
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
}
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900