دریافت اعلان‌ها برای پیام‌های ارسال شده با موفقیت و پیام‌های ناموفق

Contents
[ ]

هنگامی که می‌خواهید اعلان تحویل را برای هر دو پیام ارسال‌شده با موفقیت و ناموفق دریافت کنید، می‌توانید از عملگر لوله (|) برای 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);