Receiving Notifications for Successfully Sent and Failed Messages

[ ]

When you want to get the delivery notification for both successfully sent and failed messages, you can use the pipe (|) operator for the DeliveryNotificationOptions property of the MailMessage class. The following code snippet shows you how to receive notifications for successfully sent and failed messages.

// Create the message
MailMessage msg = new MailMessage();
msg.setSubject("the subject of the message");

// Set delivery notifications for success and failed messages and Add the MIME headers
msg.setDeliveryNotificationOptions(DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure);
msg.getHeaders().add("Read-Receipt-To", "");
msg.getHeaders().add("Disposition-Notification-To", "");

// Send the message
SmtpClient client = new SmtpClient("host", "username", "password");