When sending emails with System.Net.Mail in C#, you can specify you want certain receipts: Delivery receipts: These are the receipt emails that get sent back to you by *your* email server when it is satisfied that the email was sent to the other's server. This has no bearing on whether the other person actually saw the email, but on the other hand it doesn't require them to allow a receipt. You can get these this way:
msg.DeliveryNotificationOptions =
  DeliveryNotificationOptions.OnFailure |
  DeliveryNotificationOptions.OnSuccess |
  DeliveryNotificationOptions.Delay;
Read receipts: These are the emails that arrive in your inbox, saying something like 'the sender of this email requested a receipt upon reading it. Shall i send it?'. The receipt is optional and it requires their email client to support it, but it's a better way of gauging whether the person at the other end actually got it. Hint - i use this way, not the delivery receipts. And here's some code (change the email address!):
msg.Headers.Add("Disposition-Notification-To", "[email protected]");
And here's a complete guide to emails:
using System.Net.Mail;
...
    
MailMessage msg = new MailMessage();

msg.From = new MailAddress("[email protected]","My name");

msg.To.Add("[email protected]"); // Who's it to
msg.To.Add("[email protected]");
msg.CC.Add("[email protected]"); // CC recipient(s)
msg.CC.Add("[email protected]");

msg.Subject = "Subject line";
msg.Body = "<html><h1>Big header</h1><p>And some smaller text</p></html>"
msg.IsBodyHtml = msg.Body.Contains("<html>");

// Delivery notifications
msg.DeliveryNotificationOptions =
  DeliveryNotificationOptions.OnFailure |
  DeliveryNotificationOptions.OnSuccess |
  DeliveryNotificationOptions.Delay;
  
// Ask for a read receipt
msg.Headers.Add("Disposition-Notification-To", "[email protected]");

// Attachment(s)  
byte[] data = File.ReadAllBytes("attachment.dat");
msg.Attachments.Add(new Attachment(new MemoryStream(data),"MyAttachment.dat"));

// Send it
new SmtpClient("my-smtp-server").Send(msg);

Thanks for reading! And if you want to get in touch, I'd love to hear from you: chris.hulbert at gmail.

Chris Hulbert

(Comp Sci, Hons - UTS)

Software Developer (Freelancer / Contractor) in Australia.

I have worked at places such as Google, Cochlear, Assembly Payments, News Corp, Fox Sports, NineMSN, FetchTV, Coles, Woolworths, Trust Bank, and Westpac, among others. If you're looking for help developing an iOS app, drop me a line!

Get in touch:
[email protected]
github.com/chrishulbert
linkedin



 Subscribe via RSS