Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Commit

Permalink
Merge pull request #55 from nielsonsantana/master
Browse files Browse the repository at this point in the history
Added feature of set reply-to on the message
  • Loading branch information
dstegelman committed May 28, 2015
2 parents 984e270 + ceff483 commit db5baca
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mailqueue/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class AttachmentInline(admin.TabularInline):


class MailerAdmin(admin.ModelAdmin):
list_display = ('subject', 'to_address', 'app', 'sent', 'last_attempt')
search_fields = ['to_address', 'subject', 'app', 'bcc_address']
list_display = ('subject', 'to_address', 'app', 'sent', 'last_attempt', 'reply_to')
search_fields = ['to_address', 'subject', 'app', 'bcc_address', 'reply_to']
actions = ['send_failed']
inlines = [AttachmentInline]

Expand Down
20 changes: 20 additions & 0 deletions mailqueue/migrations/0002_mailermessage_reply_to.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('mailqueue', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='mailermessage',
name='reply_to',
field=models.TextField(max_length=250, null=True, verbose_name='Reply to', blank=True),
preserve_default=True,
),
]
6 changes: 6 additions & 0 deletions mailqueue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class MailerMessage(models.Model):
to_address = models.TextField(_('To'))
bcc_address = models.TextField(_('BCC'), blank=True)
from_address = models.EmailField(_('From'), max_length=250)
reply_to = models.TextField(_('Reply to'), max_length=250, blank=True, null=True)
content = models.TextField(_('Content'), blank=True)
html_content = models.TextField(_('HTML Content'), blank=True)
app = models.CharField(_('App'), max_length=250, blank=True)
Expand Down Expand Up @@ -99,7 +100,12 @@ def _send(self):

subject, from_email = self.subject, self.from_address
text_content = self.content

msg = EmailMultiAlternatives(subject, text_content, from_email)

if self.reply_to:
msg.extra_headers.update({"reply-to": self.reply_to})

if self.html_content:
html_content = self.html_content
msg.attach_alternative(html_content, "text/html")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding field 'MailerMessage.reply_to'
db.add_column(u'mailqueue_mailermessage', 'reply_to',
self.gf('django.db.models.fields.TextField')(max_length=250, null=True, blank=True),
keep_default=False)


def backwards(self, orm):
# Deleting field 'MailerMessage.reply_to'
db.delete_column(u'mailqueue_mailermessage', 'reply_to')


models = {
u'mailqueue.attachment': {
'Meta': {'object_name': 'Attachment'},
'email': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['mailqueue.MailerMessage']", 'null': 'True', 'blank': 'True'}),
'file_attachment': ('django.db.models.fields.files.FileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
u'mailqueue.mailermessage': {
'Meta': {'object_name': 'MailerMessage'},
'app': ('django.db.models.fields.CharField', [], {'max_length': '250', 'blank': 'True'}),
'bcc_address': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'content': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'from_address': ('django.db.models.fields.EmailField', [], {'max_length': '250'}),
'html_content': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'last_attempt': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'reply_to': ('django.db.models.fields.TextField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
'sent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'subject': ('django.db.models.fields.CharField', [], {'max_length': '250', 'blank': 'True'}),
'to_address': ('django.db.models.fields.TextField', [], {})
}
}

complete_apps = ['mailqueue']
15 changes: 15 additions & 0 deletions mailqueue/tests/test_mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.test import TestCase
from mailqueue.models import MailerMessage
from .utils import create_email


class MailerMessageTestCase(TestCase):

def test_send_mail_reply_to(self):
"""Testing creating a MailerMessage and send mail"""
reply_to = "[email protected]"
mail = create_email(reply_to=reply_to)
mail.send_mail()

self.assertEqual(mail.sent, True)
self.assertEqual(mail.reply_to, reply_to)

0 comments on commit db5baca

Please sign in to comment.