Django Test Email in Local Environment

The best solution to deal with emails locally is Mailcatcher. The blog defines the setup of mailcatcher and configure it into Django.

Mailcatcher provides you with a local SMTP server for sending and receiving emails, that sent by your web application, it provides you a clean and simple email display for testing.


Install Mailcatcher (Quick and Dirty)


1. Use following command to install mailcatcher in your local system, you can install mailcatcher by only one command, Mailcatcher is available as a ruby gem.
$ sudo gem install mailcatcher
2. Now Mail catcher is installed in your system you can verify by using the following command
$ mailcatcher --version
3. Edit settings.py file of your django project with the following code
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = '127.0.0.1'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 1025
EMAIL_USE_TLS = False
4. Run the following command where ./manage.py exists in your project
$ workon yourproject
$ honcho start mailcatcher
5. You can reach it though your browser by opening http://localhost:1080/ 

 

Install Mailcatcher (Long and Cleaner)


1. Install rbenv and ruby-build
$ brew install rbenv ruby-build

2. Install latest ruby 2.x
3. Set latest ruby as the global ruby (optional)

4. Install bundler

$ gem install bundler

5. Install mailcatcher in the yougotagift project

$ workon yourproject
$ bundle
$ honcho start (django development server, mailcatcher, celery workers and beat)

6. Edit settings_local.py with the following code

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = '127.0.0.1'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 1025
EMAIL_USE_TLS = False
 7. You can reach it though your browser by opening http://localhost:1080/

1 comment:

  1. This is why it is better that you should linked review before developing. It is possible to post superior send that way. Logo Designer

    ReplyDelete