How to use python -m smtpd to actually send emails?

703 views Asked by At

I have a Django application. In my development environment, the app is running on my Mac OSX 10.9.3 laptop. This application needs to send emails. So right now I'm using the following python process to simulate an email server.

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

This email server simply prints the email messages out to the stdout and then throws the messages away.

I would like this server to actually send the emails instead of just print them out to stdout. Can someone please advise how to do this?

1

There are 1 answers

0
denisvm On BEST ANSWER

The DebuggingServer just shows the message in stdout: https://docs.python.org/2/library/smtpd.html#debuggingserver-objects

Create a new debugging server. Arguments are as per SMTPServer. Messages will be discarded, and printed on stdout.

If you want to send e-mails directly to the internet, you have to send it through a configured MTA server, you can configure this in settings.py inside Django:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_PORT = 587

You can read more on https://docs.djangoproject.com/en/dev/ref/settings/#email-backend