emencia/emencia-django-newsletter

Disposition notification aka receipt

Opened this issue · 2 comments

RFC 3798 defines a receipt notification mechanism.
I implemented this for a client. It maybe useful for internal company message.

Of course you'll have to provide a mechanism to read receipt notification mail if it as to get into statistics.

Don't know if it's worth including.

The patch :

diff --git a/emencia/django/newsletter/admin/newsletter.py b/emencia/django/newsletter/admin/newsletter.py
index 1be8a20..53b82b8 100644
--- a/emencia/django/newsletter/admin/newsletter.py
+++ b/emencia/django/newsletter/admin/newsletter.py
@@ -41,7 +41,8 @@ class NewsletterAdmin(admin.ModelAdmin):
                  (_('Receivers'), {'fields': ('mailing_list', 'test_contacts',)}),
                  (_('Sending'), {'fields': ('sending_date', 'status',)}),
                  (_('Miscellaneous'), {'fields': ('server', 'header_sender',
-                                                  'header_reply', 'slug'),
+                                                  'header_reply', 'slug',
+                                                  'ask_receipt', 'receipt_to',),
                                        'classes': ('collapse',)}),
                  )
     prepopulated_fields = {'slug': ('title',)}
diff --git a/emencia/django/newsletter/mailer.py b/emencia/django/newsletter/mailer.py
index d38877b..aece87a 100644
--- a/emencia/django/newsletter/mailer.py
+++ b/emencia/django/newsletter/mailer.py
@@ -103,6 +124,11 @@ class Mailer(object):
         message['From'] = smart_str(self.newsletter.header_sender)
         message['Reply-to'] = smart_str(self.newsletter.header_reply)
         message['To'] = contact.mail_format()
+        if self.newsletter.ask_receipt:
+            # see RFC 3798 2.1.
+            message['Disposition-notification-to'] = (
+                          smart_str(self.newsletter.receipt_to)
+                          or smart_str(self.newsletter.header_reply) )

         message_alt = MIMEMultipart('alternative')
         message_alt.attach(MIMEText(smart_str(content_text), 'plain', 'UTF-8'))
diff --git a/emencia/django/newsletter/models.py b/emencia/django/newsletter/models.py
index c0fe9c1..e009693 100644
--- a/emencia/django/newsletter/models.py
+++ b/emencia/django/newsletter/models.py
@@ -219,6 +219,11 @@ class Newsletter(models.Model):
     header_reply = models.CharField(_('reply to'), max_length=255,
                                     default=DEFAULT_HEADER_REPLY)

+    ask_receipt = models.BooleanField(_('ask receipt'), default=True) 
+    receipt_to = models.CharField(_('send receipt to'), max_length=255,
+                                    default=DEFAULT_HEADER_REPLY,
+                                    blank=True, null=True)
+
     status = models.IntegerField(_('status'), choices=STATUS_CHOICES, default=DRAFT)
     sending_date = models.DateTimeField(_('sending date'), default=datetime.now)

On an existing EDN instance you will have to update the database with :

ALTER TABLE "newsletter_newsletter" ADD "ask_receipt" bool DEFAULT False NOT NULL;
ALTER TABLE "newsletter_newsletter" ADD  "receipt_to" varchar(255);