सफलतापूर्वक भेजे और विफल संदेशों के लिए सूचनाएँ प्राप्त करना
Contents
[
Hide
]
जब आप सफलतापूर्वक भेजे और विफल दोनों संदेशों के लिए डिलीवरी नोटिफिकेशन प्राप्त करना चाहते हैं, तो आप इसके लिए पाइप (|) ऑपरेटर का उपयोग कर सकते हैं। DeliveryNotificationOptions की प्रॉपर्टी MailMessage क्लास। निम्नलिखित कोड स्निपेट दर्शाता है कि कैसे सफलतापूर्वक भेजे और विफल संदेशों के लिए सूचनाएँ प्राप्त की जा सकती हैं।
// Create the message
MailMessage msg = new MailMessage();
msg.setFrom(MailAddress.to_MailAddress("sender@sender.com"));
msg.setTo(MailAddressCollection.to_MailAddressCollection("receiver@receiver.com"));
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", "sender@sender.com");
msg.getHeaders().add("Disposition-Notification-To", "sender@sender.com");
// Send the message
SmtpClient client = new SmtpClient("host", "username", "password");
client.send(msg);