Skip to content

Commit

Permalink
Merge pull request #11 from zack112358/master
Browse files Browse the repository at this point in the history
Add SENDMAIL_BINARY setting for systems with sendmail in an unusual location
  • Loading branch information
perenecabuto authored Jan 20, 2020
2 parents 00505e9 + c3acfe4 commit 43d239f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ Set the EMAIL_BACKEND var in your settings module

EMAIL_BACKEND = 'django_sendmail_backend.backends.EmailBackend'

If your sendmail binary is not at /usr/sbin/sendmail (see MTA section below),
you'll also need to set

SENDMAIL_BINARY = '/path/to/sendmail'


# MTA

You will need any mta installed (like postfix or exim) and a executable **sendmail** command
in your bin path.
You will need any mta installed (like postfix or exim) and a executable
**sendmail** command.

Try to install [msmtp](http://msmtp.sourceforge.net/) for test

Expand Down
5 changes: 4 additions & 1 deletion django_sendmail_backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Credits: https://djangosnippets.org/snippets/1864/
"""
from django.conf import settings
from django.core.mail.backends.base import BaseEmailBackend
from subprocess import Popen, PIPE

Expand All @@ -27,11 +28,13 @@ def send_messages(self, email_messages):
def _send(self, email_message):
"""A helper method that does the actual sending."""
recipients = email_message.recipients()
sendmail_binary = getattr(settings, 'SENDMAIL_BINARY',
'/usr/sbin/sendmail')
if not recipients:
return False
try:
# -t: Read message for recipients
ps = Popen(['/usr/sbin/sendmail'] + recipients, stdin=PIPE, stderr=PIPE)
ps = Popen([sendmail_binary] + recipients, stdin=PIPE, stderr=PIPE)
ps.stdin.write(email_message.message().as_bytes())
(stdout, stderr) = ps.communicate()
except:
Expand Down

1 comment on commit 43d239f

@Routhinator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this merge meant to generate a new version? PyPi still shows the latest as 0.1.2 from 2014.

Please sign in to comment.