Skip to content

Commit

Permalink
Various improvements / fixes - rewrite approaching
Browse files Browse the repository at this point in the history
  - sendmail: use '-t' to parse recipients from mail, instead of only
    sending to the first one
  - do not use shell=True!
  - capture stderr and use it together with returncode to raise an
    exception

Ref: perenecabuto#1
  • Loading branch information
blueyed committed Jan 11, 2014
1 parent a23cf87 commit ccbbe3e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions django_sendmail_backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
class EmailBackend(ConsoleEmailBackend):

def send_messages(self, email_messages):
recipient_email = email_messages[0].to[0]
mail_command = Popen("/usr/sbin/sendmail %s" % recipient_email, stdin=PIPE, shell=True)
# -t: Read message for recipients
mail_command = Popen(['/usr/sbin/sendmail', '-t'], stdin=PIPE, stderr=PIPE)
self.stream = mail_command.stdin

super(EmailBackend, self).send_messages(email_messages)

mail_command.communicate()
(stdout, stderr) = mail_command.communicate()

if mail_command.returncode:
raise Exception('send_messages failed: %s' % (stderr if stderr else stdout,))

0 comments on commit ccbbe3e

Please sign in to comment.