Commits

Owen Nelson committed 7d0559e

should fix #1 (sender name to help obfuscate sender email)

Comments (0)

Files changed (1)

src/trawler/models.py

 
 class Campaign(models.Model):
     title = models.CharField(max_length=45)
-    sender = models.EmailField()
+    sender_email = models.EmailField()
+    sender_name = models.CharField(max_length=60, blank=True,
+                                   help_text='Name to display for the sender'
+                                   ' (can be used to primitavely obfuscate the'
+                                   ' email address)')
     subject = models.CharField(max_length=255)
 
     email_plain = models.TextField()
     def dispatch(self, recipient, upk= -1):
         """the upk default value is so it can be safely formatted as %d 
         while still being 'invalid' """
+
+        if self.sender_name:
+            sender = "%s <%s>" % (self.sender_name, self.sender_email)
+        else:
+            sender = self.sender_email
+
         text_content = self.email_plain % dict(recipient=recipient, upk=upk,
                                                    campaign=self)
         if self.email_html:
             msg.attach_alternative(html_content, "text/html")
         else:
             # plain text only
-            msg = EmailMessage(self.subject, text_content, self.sender,
+            msg = EmailMessage(self.subject, text_content, sender,
                                [recipient])
         msg.send()