성공적으로 전송된 메시지 및 전송 실패 메시지에 대한 알림 수신
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);