From a103eaa93ed4b29c9703b18792eb85d7e229c788 Mon Sep 17 00:00:00 2001 From: Burhan Khalid Date: Wed, 8 Jul 2015 01:12:51 +0300 Subject: [PATCH 1/4] Adding support for maildump for local development (replaces the nice, but not friendly console email handler) --- {{cookiecutter.repo_name}}/Gruntfile.js | 19 +++++++++++++++++-- {{cookiecutter.repo_name}}/README.rst | 19 +++++++++++++++++++ .../config/settings/local.py | 2 -- .../requirements/local.txt | 3 +++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/{{cookiecutter.repo_name}}/Gruntfile.js b/{{cookiecutter.repo_name}}/Gruntfile.js index ba14b1e4..09d2da9c 100644 --- a/{{cookiecutter.repo_name}}/Gruntfile.js +++ b/{{cookiecutter.repo_name}}/Gruntfile.js @@ -21,7 +21,8 @@ module.exports = function (grunt) { fonts: this.app + '/static/fonts', images: this.app + '/static/images', js: this.app + '/static/js', - manageScript: 'manage.py' + manageScript: 'manage.py', + mailserverpid: 'mailserver.pid', } }; @@ -82,7 +83,13 @@ module.exports = function (grunt) { }, runDjango: { cmd: 'python <%= paths.manageScript %> runserver' - } + }, + runMailDump: { + cmd: 'maildump -p <%= paths.mailserverpid %>' + }, + stopMailDump: { + cmd: 'maildump -p <%= paths.mailserverpid %> --stop' + }, } }); @@ -98,4 +105,12 @@ module.exports = function (grunt) { grunt.registerTask('default', [ 'build' ]); + + grunt.registerTask('start-email-server', [ + 'bgShell:runMailDump' + ]); + + grunt.registerTask('stop-email-server', [ + 'bgShell:stopMailDump' + ]); }; diff --git a/{{cookiecutter.repo_name}}/README.rst b/{{cookiecutter.repo_name}}/README.rst index 54c3d305..b3e70d52 100644 --- a/{{cookiecutter.repo_name}}/README.rst +++ b/{{cookiecutter.repo_name}}/README.rst @@ -127,6 +127,25 @@ To run a celery worker: Please note: For Celerys import magic to work, it is important *where* the celery commands are run. If you are in the same folder with *manage.py*, you should be right. {% endif %} +Email Server +^^^^^^^^^^^^ + +In development, it is often nice to be able to see emails that are being sent from your application. For this purpose, +a Grunt task exists to start an instance of `maildump`_ which is a local SMTP server with an online interface. + +Make sure you have nodejs installed, and then type the following:: + + $ grunt start-email-server + +This will start an email server. The project is setup to deliver to the email server by default. To view messages +that are sent by your application, open your browser to http://127.0.0.1:1080 + +To stop the email server:: + + $ grunt stop-email-server + +The email server listens on 127.0.0.1:1025 + It's time to write the code!!! diff --git a/{{cookiecutter.repo_name}}/config/settings/local.py b/{{cookiecutter.repo_name}}/config/settings/local.py index 2124fcc6..f1342867 100644 --- a/{{cookiecutter.repo_name}}/config/settings/local.py +++ b/{{cookiecutter.repo_name}}/config/settings/local.py @@ -25,8 +25,6 @@ SECRET_KEY = env("DJANGO_SECRET_KEY", default='CHANGEME!!!') # ------------------------------------------------------------------------------ EMAIL_HOST = 'localhost' EMAIL_PORT = 1025 -EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', - default='django.core.mail.backends.console.EmailBackend') # CACHING # ------------------------------------------------------------------------------ diff --git a/{{cookiecutter.repo_name}}/requirements/local.txt b/{{cookiecutter.repo_name}}/requirements/local.txt index ea21f87a..d7b3da04 100644 --- a/{{cookiecutter.repo_name}}/requirements/local.txt +++ b/{{cookiecutter.repo_name}}/requirements/local.txt @@ -10,3 +10,6 @@ django-debug-toolbar==1.3.2 # improved REPL ipdb==0.8.1 + +# maildump +maildump==0.5.1 From 07354a3d37e80265bf5333f863cf527137789167 Mon Sep 17 00:00:00 2001 From: Burhan Khalid Date: Wed, 8 Jul 2015 01:16:18 +0300 Subject: [PATCH 2/4] Fixing links for maildump and updating master README --- README.rst | 2 ++ {{cookiecutter.repo_name}}/README.rst | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.rst b/README.rst index d74c9f59..119d801c 100644 --- a/README.rst +++ b/README.rst @@ -28,6 +28,7 @@ Features * Media storage using Amazon S3 * Serve static files from Amazon S3 or Whitenoise_ (optional) * Pre configured Celery_ (optional) +* Integration with Maildump_ for local email testing (optional) .. _Bootstrap: https://github.com/twbs/bootstrap .. _AngularJS: https://github.com/angular/angular.js @@ -39,6 +40,7 @@ Features .. _Mailgun: https://mailgun.com/ .. _Whitenoise: https://whitenoise.readthedocs.org/ .. _Celery: http://www.celeryproject.org/ +.. _Maildump: https://github.com/ThiefMaster/maildump Constraints diff --git a/{{cookiecutter.repo_name}}/README.rst b/{{cookiecutter.repo_name}}/README.rst index b3e70d52..8e86ab7f 100644 --- a/{{cookiecutter.repo_name}}/README.rst +++ b/{{cookiecutter.repo_name}}/README.rst @@ -133,6 +133,8 @@ Email Server In development, it is often nice to be able to see emails that are being sent from your application. For this purpose, a Grunt task exists to start an instance of `maildump`_ which is a local SMTP server with an online interface. +.. _maildump: https://github.com/ThiefMaster/maildump + Make sure you have nodejs installed, and then type the following:: $ grunt start-email-server From f966888ff18c99b2e8bf9cf593efa0a17cd130ea Mon Sep 17 00:00:00 2001 From: Burhan Khalid Date: Thu, 16 Jul 2015 07:21:06 +0300 Subject: [PATCH 3/4] making maildump optional --- cookiecutter.json | 1 + {{cookiecutter.repo_name}}/Gruntfile.js | 10 +++++----- {{cookiecutter.repo_name}}/README.rst | 3 ++- {{cookiecutter.repo_name}}/config/settings/local.py | 4 ++++ {{cookiecutter.repo_name}}/requirements/local.txt | 2 ++ 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index b61ca307..da0a2c94 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -11,5 +11,6 @@ "year": "{{ cookiecutter.now[:4] }}", "use_whitenoise": "y", "use_celery": "n", + "use_maildump": "n", "windows": "n" } diff --git a/{{cookiecutter.repo_name}}/Gruntfile.js b/{{cookiecutter.repo_name}}/Gruntfile.js index 09d2da9c..5686f6e9 100644 --- a/{{cookiecutter.repo_name}}/Gruntfile.js +++ b/{{cookiecutter.repo_name}}/Gruntfile.js @@ -22,7 +22,7 @@ module.exports = function (grunt) { images: this.app + '/static/images', js: this.app + '/static/js', manageScript: 'manage.py', - mailserverpid: 'mailserver.pid', + {% if cookiecutter.use_maildump=="y" -%}mailserverpid: 'mailserver.pid',{%- endif %} } }; @@ -84,12 +84,12 @@ module.exports = function (grunt) { runDjango: { cmd: 'python <%= paths.manageScript %> runserver' }, - runMailDump: { + {% if cookiecutter.use_maildump == "y" -%}runMailDump: { cmd: 'maildump -p <%= paths.mailserverpid %>' }, stopMailDump: { cmd: 'maildump -p <%= paths.mailserverpid %> --stop' - }, + },{%- endif %} } }); @@ -105,12 +105,12 @@ module.exports = function (grunt) { grunt.registerTask('default', [ 'build' ]); - + {% if cookiecutter.use_maildump == "y" -%} grunt.registerTask('start-email-server', [ 'bgShell:runMailDump' ]); grunt.registerTask('stop-email-server', [ 'bgShell:stopMailDump' - ]); + ]);{%- endif %} }; diff --git a/{{cookiecutter.repo_name}}/README.rst b/{{cookiecutter.repo_name}}/README.rst index 8e86ab7f..f5e9dd8a 100644 --- a/{{cookiecutter.repo_name}}/README.rst +++ b/{{cookiecutter.repo_name}}/README.rst @@ -126,7 +126,7 @@ To run a celery worker: Please note: For Celerys import magic to work, it is important *where* the celery commands are run. If you are in the same folder with *manage.py*, you should be right. {% endif %} - +{% if cookiecutter.use_maildump == "y" %} Email Server ^^^^^^^^^^^^ @@ -147,6 +147,7 @@ To stop the email server:: $ grunt stop-email-server The email server listens on 127.0.0.1:1025 +{% endif %} It's time to write the code!!! diff --git a/{{cookiecutter.repo_name}}/config/settings/local.py b/{{cookiecutter.repo_name}}/config/settings/local.py index f1342867..cbe5d58d 100644 --- a/{{cookiecutter.repo_name}}/config/settings/local.py +++ b/{{cookiecutter.repo_name}}/config/settings/local.py @@ -25,6 +25,10 @@ SECRET_KEY = env("DJANGO_SECRET_KEY", default='CHANGEME!!!') # ------------------------------------------------------------------------------ EMAIL_HOST = 'localhost' EMAIL_PORT = 1025 +{%if cookiecutter.use_maildump == "n" -%} +EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', + default='django.core.mail.backends.console.EmailBackend') +{%- endif %} # CACHING # ------------------------------------------------------------------------------ diff --git a/{{cookiecutter.repo_name}}/requirements/local.txt b/{{cookiecutter.repo_name}}/requirements/local.txt index d7b3da04..f46808f8 100644 --- a/{{cookiecutter.repo_name}}/requirements/local.txt +++ b/{{cookiecutter.repo_name}}/requirements/local.txt @@ -11,5 +11,7 @@ django-debug-toolbar==1.3.2 # improved REPL ipdb==0.8.1 +{% if cookiecutter.use_maildump == "y" -%} # maildump maildump==0.5.1 +{%- endif %} From a54081a761ddd647c822651c0ac18f672e04e271 Mon Sep 17 00:00:00 2001 From: Burhan Khalid Date: Thu, 16 Jul 2015 07:44:49 +0300 Subject: [PATCH 4/4] tweaking the comments to match master README --- {{cookiecutter.repo_name}}/requirements/local.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.repo_name}}/requirements/local.txt b/{{cookiecutter.repo_name}}/requirements/local.txt index f46808f8..342b5099 100644 --- a/{{cookiecutter.repo_name}}/requirements/local.txt +++ b/{{cookiecutter.repo_name}}/requirements/local.txt @@ -12,6 +12,6 @@ django-debug-toolbar==1.3.2 ipdb==0.8.1 {% if cookiecutter.use_maildump == "y" -%} -# maildump +# Enables better email testing maildump==0.5.1 {%- endif %}