Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test sending email without email server

I have a Django application that sends an email. The production server has an email server but my local box does not. I would like to be able to test sending of email locally. Is there any way that I can have django not send it through the email server and just print out to a file or console?

like image 362
asawilliams Avatar asked Jan 09 '11 21:01

asawilliams


People also ask

Can you test an email address without sending an email?

The best and most recommended ways to verify an email address without sending an email are: Email verifier tools: Use an email verification service to check if the given address is valid or not. Just google 'Email Verifier,' and many free and paid options will come up.

How can I send email without SMTP server?

The simplest way to send a message is to use QuickSend method of Smtp class (this method is static, it does not require you to create an instance of Smtp class). QuickSend method allows you to send e-mails out even if you do not have an SMTP relay server.


2 Answers

You can configure your application to use the Console Backend for sending e-mail. It writes e-mails to standard out instead of sending them.

Change your settings.py to include this line:

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' 

Don't forget to remove it for production.

like image 194
Daniel Hepper Avatar answered Sep 22 '22 14:09

Daniel Hepper


Python has a little SMTP server built-in. You can start it in a second console with this command:

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

This will simply print all the mails sent to localhost:1025 in the console.

You have to configure Django to use this server in your settings.py:

EMAIL_HOST = 'localhost' EMAIL_PORT = 1025 
like image 36
Benjamin Wohlwend Avatar answered Sep 22 '22 14:09

Benjamin Wohlwend