Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disposition notification aka receipt #34

Open
alexgarel opened this issue Mar 16, 2011 · 2 comments
Open

Disposition notification aka receipt #34

alexgarel opened this issue Mar 16, 2011 · 2 comments

Comments

@alexgarel
Copy link
Contributor

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.

@alexgarel
Copy link
Contributor Author

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)

@alexgarel
Copy link
Contributor Author

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant