Ricevere notifiche per messaggi inviati con successo e falliti
Contents
[
Hide
]
Quando si desidera ottenere la notifica di consegna sia per i messaggi inviati con successo sia per quelli falliti, è possibile usare l’operatore pipe (|) per il DeliveryNotificationOptions proprietà del MailMessage classe. Il seguente frammento di codice mostra come ricevere notifiche per messaggi inviati con successo e falliti.
// 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);