开发者

sending email django with postfix (without an explicit postfix server)

I'd like to emulate the postfix sendmail command in Django where I don't need to explicitly start up a postfix server.

For example if I simply enter the following on the command line:

sendma开发者_开发百科il recipient@example.com
my message body
^D

This will send a message to recipient@example.com. I don't need to start up a postfix server explicitly.

It seems like other languages (Perl and PHP) have bindings that will basically replicate this. However, I couldn't find a way to do it in Django/Python. The closest I got was by setting

EMAIL_HOST = 'localhost'

in settings.py and then manually doing a

postfix start

This allows the django send_mail() command to do its thing, but isn't there some way to achieve this without a running postfix server in the background? How do other environments achieve this successfully?

Thanks -S

(And no - I do not want to set up a third party gmail account to do this - that is a well worn question).


Maybe this will help you. Haven't tried it personally but seems like will suit your needs without all the trouble involved in setting a postfix server.


A simple solution to emulate email delivery is with the Python debugging server. The following runs it on port 1025 in smtp mode:

python -m smtpd -n -c DebuggingServer localhost:1025

You will need to ensure that your Django testing server is firing email at port 1025 on localhost though, so you might need this in your settings.py:

EMAIL_PORT = 1025

When that's working correctly, the testing server will just echo all the mail sent by your Django directly to the terminal so you can keep an eye on the output while in development. I've used this recently when I struggled to get postfix working on an Ubuntu box - it was just hanging and breaking the Django test server on send_mail().

Here is the Django doc with more info on email testing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜