In this post I am going to explain about email delivery notification in .NET. Delivery notifications used to trace the mail delivered or not and when it is delivered and is any delay in sending e-mail..!. Once mail is delivered to the recipient mailbox and delivery notification mail will be sent to the sender mailbox in case of delay or fail to delivery the mail server will send a mail back to sender.
We can set delivery notification in mail in C#.NET easily same in VB.NET. How we can do this? please check with this below code.. It is normal mail sending only. we need to and one more line to set delivery notification.
using System.Net.Mail; //Most import System.Net.Mail
SmtpClient smtp = new SmtpClient();
MailMessage msg = new MailMessage(firstname.lastname@example.org, “email@example.com”);
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess; //– This is for set delivery notification mail On Success
//msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; //– This is for set delivery notification mail On Failure
msg.Subject = “This is for Demo”;
msg.Body = “This is just for demo about delivery notification option mail option in C#“;
In this code it use our smtp setting to send mail, which are configured in web.config or local smtp settings (Tip:- use Web Site Administration Tool to set STMP settings).
This about code for getting delivery notification on success only. If you want to use of on failure. use below line. If you want to sent all notifications use this below line
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure | DeliveryNotificationOptions.Delay; //this is line for set all, to sent all delivery notifications, we need to use or(|) between them..
Please check with table more details about delivery notification options..
|Delay||Notify if the delivery is delayed.|
|Never||A notification should not be generated under any circumstances.|
|None||No notification information will be sent. The mail server will utilize its configured behavior to determine whether it should generate a delivery notification.|
|OnFailure||Notify if the delivery is unsuccessful.|
|OnSuccess||Notify if the delivery is successful.|
|for more details http://msdn.microsoft.com/en-us/library/system.net.mail.deliverynotificationoptions.aspx|
I hope this code helpful for you..!
Enjoy while coding..!
Naga Harish Movva.