{"id":3857,"date":"2013-03-27T13:30:24","date_gmt":"2013-03-27T11:30:24","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=3857"},"modified":"2017-03-19T11:59:25","modified_gmt":"2017-03-19T09:59:25","slug":"creating-read-receipt-mdn","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/creating-read-receipt-mdn","title":{"rendered":"Creating read receipt (MDN)"},"content":{"rendered":"<div class=\"well\">\n<ul>\nYou can also read how to: <\/p>\n<li><a href=\"\/blog\/requesting-read-receipt\">Request a read receipt<\/a><\/li>\n<li>Create a read receipt<\/li>\n<li><a href=\"\/blog\/processing-read-receipt-mdn\">Process a read receipt<\/a><\/li>\n<\/ul>\n<\/div>\n<p>In this article we&#8217;ll show how to create and send read receipt.<\/p>\n<p>Read receipts also known as MDNs or Message Delivery Notifications are used to notify the message sender that some action has happened with their message (it was displayed, processed, deleted)<\/p>\n<h2>Check if read receipt was requested<\/h2>\n<p>Although several email headers can be used by sender to request a read receipt (&#8216;Disposition-Notification-To&#8217;, &#8216;Return-Receipt-To&#8217;, &#8216;X-Confirm-Reading-To&#8217;) checking if read receipt was requested is quite easy. You just need to use <em>IMail.GetReadReceiptAddresses<\/em> method.<\/p>\n<p>This method checks all previously mentioned headers and removes duplicates. If the returned list is not empty, it means that sender have requested read receipt.<\/p>\n<p>The recipient&#8217;s email software may silently ignore the request, or it may prompt the user for permission to send the MDN. There is no obligation or guarantee of the return-receipt sending. <\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nIMail mail = ...\r\n\r\nList&lt;MailBox&gt; addresses = mail.GetReadReceiptAddresses();\r\nif (addresses.Count &gt; 0)\r\n{\r\n    \/\/ Read receipt was requested\r\n}\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim mail As IMail = ...\r\n\r\nDim addresses As List(Of MailBox) = mail.GetReadReceiptAddresses()\r\n    ' Read receipt was requested\r\nIf addresses.Count &gt; 0 Then\r\nEnd If\r\n<\/pre>\n<h2>Creating read receipt for a message<\/h2>\n<p>Use <em>ReadReceiptBuilder<\/em> class to create <em>MailBuilder <\/em>that can be used to create actual message (<em>IMail<\/em>).<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\nIMail mail = ...\r\n\r\nReadReceiptBuilder mdnBuilder = new ReadReceiptBuilder(mail);\r\n\/\/mdnBuilder.ReadSubjectTemplate = &quot;Read: &#x5B;Original.Subject]&quot;;\r\n\/\/mdnBuilder.ReadTextTemplate = \r\n\/\/  @&quot;This is a confirmation that your message sent to &#x5B;OriginalRecipient.Address] was displayed.&quot;;\r\nMailBuilder builder = mdnBuilder.WasDisplayed(new MailBox(&quot;bob@example.com&quot;));\r\nIMail mdn = builder.Create();\r\n\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim mail As IMail = ...\r\n\r\nDim mdnBuilder As New ReadReceiptBuilder(mail)\r\n'mdnBuilder.ReadSubjectTemplate = &quot;Read: &#x5B;Original.Subject]&quot;;\r\n'mdnBuilder.ReadTextTemplate =  \r\n'   @&quot;This is a confirmation that your message sent to &#x5B;OriginalRecipient.Address] was displayed.&quot;;\r\nDim builder As MailBuilder = mdnBuilder.WasDisplayed(New MailBox(&quot;bob@example.com&quot;))\r\nDim mdn As IMail = builder.Create()\r\n<\/pre>\n<h2>Creating new read receipt<\/h2>\n<p>You can use <em>ReadReceiptBuilder <\/em>constructor overloads to create new read receipt when you don&#8217;t have IMail object available. You&#8217;ll need original message-id however.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nReadReceiptBuilder mdnBuilder = new ReadReceiptBuilder(&quot;messageid@original.com&quot;, new MailBox(&quot;sender@original.com&quot;));\r\nMailBuilder builder = mdnBuilder.WasDisplayed(new MailBox(&quot;recipient@original.com&quot;));\r\nIMail mdn = builder.Create();\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim mdnBuilder As New ReadReceiptBuilder(&quot;messageid@original.com&quot;, New MailBox(&quot;sender@original.com&quot;))\r\nDim builder As MailBuilder = mdnBuilder.WasDisplayed(New MailBox(&quot;recipient@original.com&quot;))\r\nDim mdn As IMail = builder.Create()\r\n<\/pre>\n<h2>Sending read receipt<\/h2>\n<p>There some restrictions regarding sending MDNs that you should consider, <a href=\"\/mail\/rfc\/3798\">RFC 3798<\/a>:<\/p>\n<blockquote><p>\n   MDNs SHOULD NOT be sent automatically if the address in the<br \/>\n   Disposition-Notification-To header differs from the address in the<br \/>\n   Return-Path header (<em>IMail.ReturnPath<\/em>). In this case, confirmation<br \/>\n   from the user SHOULD be obtained, if possible.  If obtaining consent<br \/>\n   is not possible (e.g., because the user is not online at the time),<br \/>\n   then an MDN SHOULD NOT be sent.\n<\/p><\/blockquote>\n<blockquote><p>\nConfirmation from the user SHOULD be obtained (or no MDN sent) if<br \/>\n   there is no Return-Path header (<em>IMail.ReturnPath<\/em>) in the message, or if there is more<br \/>\n   than one distinct address in the Disposition-Notification-To header (<em>IMail.GetReadReceiptAddresses<\/em>).\n<\/p><\/blockquote>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nusing(Smtp smtp = new Smtp())\r\n{\r\n    smtp.Connect(&quot;smtp.server.com&quot;);  \/\/ or ConnectSSL for SSL\r\n    smtp.UseBestLogin(&quot;user&quot;, &quot;password&quot;);\r\n \r\n    smtp.SendMessage(mdn);                     \r\n \r\n    smtp.Close();   \r\n}  \r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nUsing smtp As New Smtp()\r\n    smtp.Connect(&quot;smtp.server.com&quot;)\t' or ConnectSSL for SSL\r\n    smtp.UseBestLogin(&quot;user&quot;, &quot;password&quot;)\r\n\r\n    smtp.SendMessage(mdn)\r\n\r\n    smtp.Close()\r\nEnd Using\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You can also read how to: Request a read receipt Create a read receipt Process a read receipt In this article we&#8217;ll show how to create and send read receipt. Read receipts also known as MDNs or Message Delivery Notifications are used to notify the message sender that some action has happened with their message [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,33,95,50,57],"class_list":["post-3857","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-email-component","tag-mdn","tag-smtp","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3857"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=3857"}],"version-history":[{"count":24,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3857\/revisions"}],"predecessor-version":[{"id":5332,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3857\/revisions\/5332"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=3857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=3857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=3857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}