From 6709fc64c9f16d534a2f156b48425061ec01c7a8 Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Thu, 6 Feb 2020 15:17:46 -0500 Subject: [PATCH 01/11] Added all supported Anymail Providers in cookiecutter.json * Utilizes {% if %} since it's financially more wise to use AWS SES only if AWS is the cloud provider. * FIXME: If AWS is not cloud provider, there are two None options. This may require a little hack inside of cookiecutter that I may not be aware of. --- cookiecutter.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cookiecutter.json b/cookiecutter.json index 4e77d110..5efa745e 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -33,6 +33,18 @@ "GCP", "None" ], + "mail_service": [ + "{% if cookiecutter.cloud_provider == 'AWS' %}Amazon SES{% else %}Mailgun{% endif %}", + "{% if cookiecutter.cloud_provider == 'AWS' %}Mailgun{% else %}Mailjet{% endif %}", + "{% if cookiecutter.cloud_provider == 'AWS' %}Mailjet{% else %}Mandrill{% endif %}", + "{% if cookiecutter.cloud_provider == 'AWS' %}Mandrill{% else %}Postmark{% endif %}", + "{% if cookiecutter.cloud_provider == 'AWS' %}Postmark{% else %}Sendgrid{% endif %}", + "{% if cookiecutter.cloud_provider == 'AWS' %}Sendgrid{% else %}SendinBlue{% endif %}", + "{% if cookiecutter.cloud_provider == 'AWS' %}SendinBlue{% else %}SparkPost{% endif %}", + "{% if cookiecutter.cloud_provider == 'AWS' %}SparkPost{% else %}Plain Django-Anymail{% endif %}", + "{% if cookiecutter.cloud_provider == 'AWS' %}Plain Django-Anymail{% else %}None{% endif %}", + "{% if cookiecutter.cloud_provider == 'AWS' %}None{% else %}None{% endif %}" + ], "use_drf": "n", "custom_bootstrap_compilation": "n", "use_compressor": "n", From b7d3379f4405e38df62fe097b10a3df2a608e9a5 Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Thu, 6 Feb 2020 15:36:51 -0500 Subject: [PATCH 02/11] Fixes the duplicate None in cookiecutter.json * The duplicate occurs if AWS is not the selected cloud provider --- cookiecutter.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index 5efa745e..cbe3cbf7 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -34,16 +34,16 @@ "None" ], "mail_service": [ - "{% if cookiecutter.cloud_provider == 'AWS' %}Amazon SES{% else %}Mailgun{% endif %}", - "{% if cookiecutter.cloud_provider == 'AWS' %}Mailgun{% else %}Mailjet{% endif %}", - "{% if cookiecutter.cloud_provider == 'AWS' %}Mailjet{% else %}Mandrill{% endif %}", - "{% if cookiecutter.cloud_provider == 'AWS' %}Mandrill{% else %}Postmark{% endif %}", - "{% if cookiecutter.cloud_provider == 'AWS' %}Postmark{% else %}Sendgrid{% endif %}", - "{% if cookiecutter.cloud_provider == 'AWS' %}Sendgrid{% else %}SendinBlue{% endif %}", - "{% if cookiecutter.cloud_provider == 'AWS' %}SendinBlue{% else %}SparkPost{% endif %}", - "{% if cookiecutter.cloud_provider == 'AWS' %}SparkPost{% else %}Plain Django-Anymail{% endif %}", - "{% if cookiecutter.cloud_provider == 'AWS' %}Plain Django-Anymail{% else %}None{% endif %}", - "{% if cookiecutter.cloud_provider == 'AWS' %}None{% else %}None{% endif %}" + {% if cookiecutter.cloud_provider == 'AWS' %}"Amazon SES",{% endif %} + "Mailgun", + "Mailjet", + "Mandrill", + "Postmark", + "Sendgrid", + "SendinBlue", + "SparkPost", + "Plain/Vanilla Django-Anymail", + "None" ], "use_drf": "n", "custom_bootstrap_compilation": "n", From 575dead7cb3e7c04ff7d7133575af32540c94bbf Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Thu, 6 Feb 2020 16:00:32 -0500 Subject: [PATCH 03/11] More concise cookiecutter.json; removed several if statements * Unfortunately, with https://github.com/pydanny/cookiecutter-django/pull/2321#issuecomment-558796906, I don't think I am going to add AWS SES specifically if AWS is not chosen as cloud provider. In that case, we'll just deal with 2 None's when AWS is not selected. * FIXME 2 Nones --- cookiecutter.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookiecutter.json b/cookiecutter.json index cbe3cbf7..ae0576b5 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -34,7 +34,7 @@ "None" ], "mail_service": [ - {% if cookiecutter.cloud_provider == 'AWS' %}"Amazon SES",{% endif %} + "{% if cookiecutter.cloud_provider == 'AWS' %}Amazon SES{% else %}None{% endif %}", "Mailgun", "Mailjet", "Mandrill", From c8eb5462eb921313d3fbb9a9957125022d444cd3 Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Thu, 6 Feb 2020 16:58:15 -0500 Subject: [PATCH 04/11] Configurations and Packages added * Production settings updated for all * Added env vars from production settings * Added packages requirements.txt --- .../.envs/.production/.django | 19 ++++++- .../config/settings/production.py | 52 ++++++++++++++++++- .../requirements/production.txt | 18 +++++++ 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/{{cookiecutter.project_slug}}/.envs/.production/.django b/{{cookiecutter.project_slug}}/.envs/.production/.django index 2c2e94f2..358b5e95 100644 --- a/{{cookiecutter.project_slug}}/.envs/.production/.django +++ b/{{cookiecutter.project_slug}}/.envs/.production/.django @@ -13,9 +13,26 @@ DJANGO_SECURE_SSL_REDIRECT=False # Email # ------------------------------------------------------------------------------ -MAILGUN_API_KEY= DJANGO_SERVER_EMAIL= +{% if cookiecutter.mail_service == 'Mailgun' %} +MAILGUN_API_KEY= MAILGUN_DOMAIN= +{% elif cookiecutter.mail_service == 'Mailjet' %} +MAILJET_API_KEY= +MAILJET_SECRET_KEY= +{% elif cookiecutter.mail_service == 'Mandrill' %} +MANDRILL_API_KEY= +{% elif cookiecutter.mail_service == 'Postmark' %} +POSTMARK_SERVER_TOKEN= +{% elif cookiecutter.mail_service == 'Sendgrid' %} +SENDGRID_API_KEY= +SENDGRID_GENERATE_MESSAGE_ID=True +SENDGRID_MERGE_FIELD_FORMAT=None +{% elif cookiecutter.mail_service == 'SendinBlue' %} +SENDINBLUE_API_KEY= +{% elif cookiecutter.mail_service == 'SparkPost' %} +SPARKPOST_API_KEY= +{% endif %} {% if cookiecutter.cloud_provider == 'AWS' %} # AWS # ------------------------------------------------------------------------------ diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 36667b33..e0af4c59 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -182,16 +182,66 @@ EMAIL_SUBJECT_PREFIX = env( # Django Admin URL regex. ADMIN_URL = env("DJANGO_ADMIN_URL") -# Anymail (Mailgun) +# Anymail # ------------------------------------------------------------------------------ # https://anymail.readthedocs.io/en/stable/installation/#installing-anymail INSTALLED_APPS += ["anymail"] # noqa F405 +{%- if cookiecutter.mail_service == 'Amazon SES' %} +EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend" +# https://anymail.readthedocs.io/en/stable/esps/amazon_ses/ +{%- elif cookiecutter.mail_service == 'Mailgun' %} EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend" +# https://anymail.readthedocs.io/en/stable/esps/mailgun/ +{%- elif cookiecutter.mail_service == 'Mailjet' %} +EMAIL_BACKEND = "anymail.backends.mailjet.EmailBackend" +# https://anymail.readthedocs.io/en/stable/esps/mailjet/ +{%- elif cookiecutter.mail_service == 'Mandrill' %} +EMAIL_BACKEND = "anymail.backends.mandrill.EmailBackend" +# https://anymail.readthedocs.io/en/stable/esps/mandrill/ +{%- elif cookiecutter.mail_service == 'Postmark' %} +EMAIL_BACKEND = "anymail.backends.postmark.EmailBackend" +# https://anymail.readthedocs.io/en/stable/esps/postmark/ +{%- elif cookiecutter.mail_service == 'Sendgrid' %} +EMAIL_BACKEND = "anymail.backends.sendgrid.EmailBackend" +# https://anymail.readthedocs.io/en/stable/esps/sendgrid/ +{%- elif cookiecutter.mail_service == 'SendinBlue' %} +EMAIL_BACKEND = "anymail.backends.sendinblue.EmailBackend" +# https://anymail.readthedocs.io/en/stable/esps/sendinblue/ +{%- elif cookiecutter.mail_service == 'SparkPost' %} +EMAIL_BACKEND = "anymail.backends.sparkpost.EmailBackend" +# https://anymail.readthedocs.io/en/stable/esps/sparkpost/ +{%- elif cookiecutter.mail_service == 'Plain/Vanilla Django-Anymail' %} +EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" +# https://docs.djangoproject.com/en/3.0/ref/settings/#email-backend +{%- endif %} # https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference ANYMAIL = { + {%- if cookiecutter.mail_service == 'Mailgun' %} "MAILGUN_API_KEY": env("MAILGUN_API_KEY"), "MAILGUN_SENDER_DOMAIN": env("MAILGUN_DOMAIN"), "MAILGUN_API_URL": env("MAILGUN_API_URL", default="https://api.mailgun.net/v3"), + {%- elif cookiecutter.mail_service == 'Mailjet' %} + "MAILJET_API_KEY": env("MAILJET_API_KEY"), + "MAILJET_SECRET_KEY": env("MAILJET_SECRET_KEY"), + "MAILJET_API_URL": env("MAILJET_API_URL", default="https://api.mailjet.com/v3"), + {%- elif cookiecutter.mail_service == 'Mandrill' %} + "MANDRILL_API_KEY": env("MANDRILL_API_KEY"), + "MANDRILL_API_URL": env("MANDRILL_API_URL", default="https://mandrillapp.com/api/1.0"), + {%- elif cookiecutter.mail_service == 'Postmark' %} + "POSTMARK_SERVER_TOKEN": env("POSTMARK_SERVER_TOKEN"), + "POSTMARK_API_URL": env("POSTMARK_API_URL", default="https://api.postmarkapp.com/"), + {%- elif cookiecutter.mail_service == 'Sendgrid' %} + "SENDGRID_API_KEY": env("SENDGRID_API_KEY"), + "SENDGRID_GENERATE_MESSAGE_ID": env("SENDGRID_GENERATE_MESSAGE_ID"), + "SENDGRID_MERGE_FIELD_FORMAT": env("SENDGRID_MERGE_FIELD_FORMAT"), + "SENDGRID_API_URL": env("SENDGRID_API_URL", default="https://api.sendgrid.com/v3/"), + {%- elif cookiecutter.mail_service == 'SendinBlue' %} + "SENDINBLUE_API_KEY": env("SENDINBLUE_API_KEY"), + "SENDINBLUE_API_URL": env("SENDINBLUE_API_URL", default="https://api.sendinblue.com/v3/"), + {%- elif cookiecutter.mail_service == 'SparkPost' %} + "SPARKPOST_API_KEY": env("SPARKPOST_API_KEY"), + "SPARKPOST_API_URL": env("SPARKPOST_API_URL", default="https://api.sparkpost.com/api/v1"), + {%- endif %} } {% if cookiecutter.use_compressor == 'y' -%} diff --git a/{{cookiecutter.project_slug}}/requirements/production.txt b/{{cookiecutter.project_slug}}/requirements/production.txt index 9c1de827..3e1d8515 100644 --- a/{{cookiecutter.project_slug}}/requirements/production.txt +++ b/{{cookiecutter.project_slug}}/requirements/production.txt @@ -18,4 +18,22 @@ django-storages[boto3]==1.9.1 # https://github.com/jschneier/django-storages {%- elif cookiecutter.cloud_provider == 'GCP' %} django-storages[google]==1.9.1 # https://github.com/jschneier/django-storages {%- endif %} +{%- if cookiecutter.mail_service == 'Amazon SES' %} +django-anymail[amazon_ses]==7.0.0 # https://github.com/anymail/django-anymail +{%- elif cookiecutter.mail_service == 'Mailgun' %} django-anymail[mailgun]==7.0.0 # https://github.com/anymail/django-anymail +{%- elif cookiecutter.mail_service == 'Mailjet' %} +django-anymail[mailjet]==7.0.0 # https://github.com/anymail/django-anymail +{%- elif cookiecutter.mail_service == 'Mandrill' %} +django-anymail[mandrill]==7.0.0 # https://github.com/anymail/django-anymail +{%- elif cookiecutter.mail_service == 'Postmark' %} +django-anymail[postmark]==7.0.0 # https://github.com/anymail/django-anymail +{%- elif cookiecutter.mail_service == 'Sendgrid' %} +django-anymail[sendgrid]==7.0.0 # https://github.com/anymail/django-anymail +{%- elif cookiecutter.mail_service == 'SendinBlue' %} +django-anymail[sendinblue]==7.0.0 # https://github.com/anymail/django-anymail +{%- elif cookiecutter.mail_service == 'SparkPost' %} +django-anymail[sparkpost]==7.0.0 # https://github.com/anymail/django-anymail +{%- elif cookiecutter.mail_service == 'Plain/Vanilla Django-Anymail' %} +django-anymail==7.0.0 # https://github.com/anymail/django-anymail +{%- endif %} From fecf9e0037885bac16228ac3bd8060f04f83375b Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Thu, 6 Feb 2020 16:59:42 -0500 Subject: [PATCH 05/11] Add @Andrew-Chen-Wang to CONTRIBUTORS --- CONTRIBUTORS.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 2554d2cf..6dca6ddb 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -56,6 +56,7 @@ Listed in alphabetical order. Andreas Meistad `@ameistad`_ Andres Gonzalez `@andresgz`_ Andrew Mikhnevich `@zcho`_ + Andrew Chen Wang `@Andrew-Chen-Wang`_ Andy Rose Anna Callahan `@jazztpt`_ Anna Sidwell `@takkaria`_ @@ -228,6 +229,7 @@ Listed in alphabetical order. .. _@andor-pierdelacabeza: https://github.com/andor-pierdelacabeza .. _@andresgz: https://github.com/andresgz .. _@antoniablair: https://github.com/antoniablair +.. _@Andrew-Chen-Wang: https://github.com/Andrew-Chen-Wang .. _@apirobot: https://github.com/apirobot .. _@archinal: https://github.com/archinal .. _@areski: https://github.com/areski From 0621929cd2889892106d853a9a2cd3b0a491f73c Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Thu, 6 Feb 2020 18:41:30 -0500 Subject: [PATCH 06/11] Removed None option for mail service * This is necessary in order to be compatible with Django-allauth --- cookiecutter.json | 5 ++--- .../config/settings/production.py | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index ae0576b5..5e85af48 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -34,7 +34,7 @@ "None" ], "mail_service": [ - "{% if cookiecutter.cloud_provider == 'AWS' %}Amazon SES{% else %}None{% endif %}", + "{% if cookiecutter.cloud_provider == 'AWS' %}Amazon SES{% else %}Plain/Vanilla Django-Anymail{% endif %}", "Mailgun", "Mailjet", "Mandrill", @@ -42,8 +42,7 @@ "Sendgrid", "SendinBlue", "SparkPost", - "Plain/Vanilla Django-Anymail", - "None" + "Plain/Vanilla Django-Anymail" ], "use_drf": "n", "custom_bootstrap_compilation": "n", diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index e0af4c59..6d431800 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -188,59 +188,60 @@ ADMIN_URL = env("DJANGO_ADMIN_URL") INSTALLED_APPS += ["anymail"] # noqa F405 {%- if cookiecutter.mail_service == 'Amazon SES' %} EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend" -# https://anymail.readthedocs.io/en/stable/esps/amazon_ses/ {%- elif cookiecutter.mail_service == 'Mailgun' %} EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend" -# https://anymail.readthedocs.io/en/stable/esps/mailgun/ {%- elif cookiecutter.mail_service == 'Mailjet' %} EMAIL_BACKEND = "anymail.backends.mailjet.EmailBackend" -# https://anymail.readthedocs.io/en/stable/esps/mailjet/ {%- elif cookiecutter.mail_service == 'Mandrill' %} EMAIL_BACKEND = "anymail.backends.mandrill.EmailBackend" -# https://anymail.readthedocs.io/en/stable/esps/mandrill/ {%- elif cookiecutter.mail_service == 'Postmark' %} EMAIL_BACKEND = "anymail.backends.postmark.EmailBackend" -# https://anymail.readthedocs.io/en/stable/esps/postmark/ {%- elif cookiecutter.mail_service == 'Sendgrid' %} EMAIL_BACKEND = "anymail.backends.sendgrid.EmailBackend" -# https://anymail.readthedocs.io/en/stable/esps/sendgrid/ {%- elif cookiecutter.mail_service == 'SendinBlue' %} EMAIL_BACKEND = "anymail.backends.sendinblue.EmailBackend" -# https://anymail.readthedocs.io/en/stable/esps/sendinblue/ {%- elif cookiecutter.mail_service == 'SparkPost' %} EMAIL_BACKEND = "anymail.backends.sparkpost.EmailBackend" -# https://anymail.readthedocs.io/en/stable/esps/sparkpost/ {%- elif cookiecutter.mail_service == 'Plain/Vanilla Django-Anymail' %} EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" # https://docs.djangoproject.com/en/3.0/ref/settings/#email-backend {%- endif %} # https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference ANYMAIL = { - {%- if cookiecutter.mail_service == 'Mailgun' %} + {%- if cookiecutter.mail_service == 'Amazon SES' %} + # https://anymail.readthedocs.io/en/stable/esps/amazon_ses/ + {%- elif cookiecutter.mail_service == 'Mailgun' %} "MAILGUN_API_KEY": env("MAILGUN_API_KEY"), "MAILGUN_SENDER_DOMAIN": env("MAILGUN_DOMAIN"), "MAILGUN_API_URL": env("MAILGUN_API_URL", default="https://api.mailgun.net/v3"), + # https://anymail.readthedocs.io/en/stable/esps/mailgun/ {%- elif cookiecutter.mail_service == 'Mailjet' %} "MAILJET_API_KEY": env("MAILJET_API_KEY"), "MAILJET_SECRET_KEY": env("MAILJET_SECRET_KEY"), "MAILJET_API_URL": env("MAILJET_API_URL", default="https://api.mailjet.com/v3"), + # https://anymail.readthedocs.io/en/stable/esps/mailjet/ {%- elif cookiecutter.mail_service == 'Mandrill' %} "MANDRILL_API_KEY": env("MANDRILL_API_KEY"), "MANDRILL_API_URL": env("MANDRILL_API_URL", default="https://mandrillapp.com/api/1.0"), + # https://anymail.readthedocs.io/en/stable/esps/mandrill/ {%- elif cookiecutter.mail_service == 'Postmark' %} "POSTMARK_SERVER_TOKEN": env("POSTMARK_SERVER_TOKEN"), "POSTMARK_API_URL": env("POSTMARK_API_URL", default="https://api.postmarkapp.com/"), + # https://anymail.readthedocs.io/en/stable/esps/postmark/ {%- elif cookiecutter.mail_service == 'Sendgrid' %} "SENDGRID_API_KEY": env("SENDGRID_API_KEY"), "SENDGRID_GENERATE_MESSAGE_ID": env("SENDGRID_GENERATE_MESSAGE_ID"), "SENDGRID_MERGE_FIELD_FORMAT": env("SENDGRID_MERGE_FIELD_FORMAT"), "SENDGRID_API_URL": env("SENDGRID_API_URL", default="https://api.sendgrid.com/v3/"), + # https://anymail.readthedocs.io/en/stable/esps/sendgrid/ {%- elif cookiecutter.mail_service == 'SendinBlue' %} "SENDINBLUE_API_KEY": env("SENDINBLUE_API_KEY"), "SENDINBLUE_API_URL": env("SENDINBLUE_API_URL", default="https://api.sendinblue.com/v3/"), + # https://anymail.readthedocs.io/en/stable/esps/sendinblue/ {%- elif cookiecutter.mail_service == 'SparkPost' %} "SPARKPOST_API_KEY": env("SPARKPOST_API_KEY"), "SPARKPOST_API_URL": env("SPARKPOST_API_URL", default="https://api.sparkpost.com/api/v1"), + # https://anymail.readthedocs.io/en/stable/esps/sparkpost/ {%- endif %} } From ac884f3f75fa7f5b25f6a754a452193cd037b318 Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Thu, 6 Feb 2020 20:18:49 -0500 Subject: [PATCH 07/11] Updated mail service docs * Trying to appease the Black-linter god... --- README.rst | 4 +-- docs/project-generation-options.rst | 23 ++++++++++++ docs/settings.rst | 15 ++++++++ .../config/settings/production.py | 36 +++++++++++++++---- 4 files changed, 69 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index 6e534b0f..1d43b84e 100644 --- a/README.rst +++ b/README.rst @@ -46,7 +46,7 @@ Features * Registration via django-allauth_ * Comes with custom user model ready to go * Optional custom static build using Gulp and livereload -* Send emails via Anymail_ (using Mailgun_ by default, but switchable) +* Send emails via Anymail_ (using Mailgun_ by default or Amazon SES if AWS is selected cloud provider, but switchable) * Media storage using Amazon S3 or Google Cloud Storage * Docker support using docker-compose_ for development and production (using Traefik_ with LetsEncrypt_ support) * Procfile_ for deploying to Heroku @@ -85,7 +85,7 @@ Optional Integrations .. _PythonAnywhere: https://www.pythonanywhere.com/ .. _Traefik: https://traefik.io/ .. _LetsEncrypt: https://letsencrypt.org/ -.. _pre-commit: https://github.com/pre-commit/pre-commit +.. _pre-commit: https://github.com/pre-commit/pre-commit Constraints ----------- diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index 2ed77fac..87ae90b1 100644 --- a/docs/project-generation-options.rst +++ b/docs/project-generation-options.rst @@ -70,6 +70,19 @@ cloud_provider: Note that if you choose no cloud provider, media files won't work. +mail_service: + Select an email service that Django-Anymail provides + + 1. Amazon SES_ + 2. Mailgun_ + 3. Mailjet_ + 4. Mandrill_ + 5. Postmark_ + 6. SendGrid_ + 7. SendinBlue_ + 8. SparkPost_ + 9. Plain/Vanilla Django-Anymail_ + use_drf: Indicates whether the project should be configured to use `Django Rest Framework`_. @@ -132,6 +145,16 @@ debug: .. _AWS: https://aws.amazon.com/s3/ .. _GCP: https://cloud.google.com/storage/ +.. _SES: https://aws.amazon.com/ses/ +.. _Mailgun: https://www.mailgun.com +.. _Mailjet: https://www.mailjet.com +.. _Mandrill: http://mandrill.com +.. _Postmark: https://postmarkapp.com +.. _SendGrid: https://sendgrid.com +.. _SendinBlue: https://www.sendinblue.com +.. _SparkPost: https://www.sparkpost.com +.. _Django-Anymail: https://anymail.readthedocs.io/en/stable/ + .. _Django Rest Framework: https://github.com/encode/django-rest-framework/ .. _Django Compressor: https://github.com/django-compressor/django-compressor diff --git a/docs/settings.rst b/docs/settings.rst index e586c963..2ae8814e 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -52,6 +52,21 @@ DJANGO_SENTRY_LOG_LEVEL SENTRY_LOG_LEVEL n/a MAILGUN_API_KEY MAILGUN_API_KEY n/a raises error MAILGUN_DOMAIN MAILGUN_SENDER_DOMAIN n/a raises error MAILGUN_API_URL n/a n/a "https://api.mailgun.net/v3" +MAILJET_API_KEY MAILJET_API_KEY n/a raises error +MAILJET_SECRET_KEY MAILJET_SECRET_KEY n/a raises error +MAILJET_API_URL n/a n/a "https://api.mailjet.com/v3" +MANDRILL_API_KEY MANDRILL_API_KEY n/a raises error +MANDRILL_API_URL n/a n/a "https://mandrillapp.com/api/1.0" +POSTMARK_SERVER_TOKEN POSTMARK_SERVER_TOKEN n/a raises error +POSTMARK_API_URL n/a n/a "https://api.postmarkapp.com/" +SENDGRID_API_KEY SENDGRID_API_KEY n/a raises error +SENDGRID_GENERATE_MESSAGE_ID True n/a raises error +SENDGRID_MERGE_FIELD_FORMAT None n/a raises error +SENDGRID_API_URL n/a n/a "https://api.sendgrid.com/v3/" +SENDINBLUE_API_KEY SENDINBLUE_API_KEY n/a raises error +SENDINBLUE_API_URL n/a n/a "https://api.sendinblue.com/v3/" +SPARKPOST_API_KEY SPARKPOST_API_KEY n/a raises error +SPARKPOST_API_URL n/a n/a "https://api.sparkpost.com/api/v1" ======================================= =========================== ============================================== ====================================================================== -------------------------- diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 6d431800..57b8eb39 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -208,39 +208,61 @@ EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" {%- endif %} # https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference ANYMAIL = { + # https://anymail.readthedocs.io/en/stable/esps/ {%- if cookiecutter.mail_service == 'Amazon SES' %} # https://anymail.readthedocs.io/en/stable/esps/amazon_ses/ {%- elif cookiecutter.mail_service == 'Mailgun' %} "MAILGUN_API_KEY": env("MAILGUN_API_KEY"), "MAILGUN_SENDER_DOMAIN": env("MAILGUN_DOMAIN"), - "MAILGUN_API_URL": env("MAILGUN_API_URL", default="https://api.mailgun.net/v3"), + "MAILGUN_API_URL": env( + "MAILGUN_API_URL", + default="https://api.mailgun.net/v3" + ), # https://anymail.readthedocs.io/en/stable/esps/mailgun/ {%- elif cookiecutter.mail_service == 'Mailjet' %} "MAILJET_API_KEY": env("MAILJET_API_KEY"), "MAILJET_SECRET_KEY": env("MAILJET_SECRET_KEY"), - "MAILJET_API_URL": env("MAILJET_API_URL", default="https://api.mailjet.com/v3"), + "MAILJET_API_URL": env( + "MAILJET_API_URL", + default="https://api.mailjet.com/v3" + ), # https://anymail.readthedocs.io/en/stable/esps/mailjet/ {%- elif cookiecutter.mail_service == 'Mandrill' %} "MANDRILL_API_KEY": env("MANDRILL_API_KEY"), - "MANDRILL_API_URL": env("MANDRILL_API_URL", default="https://mandrillapp.com/api/1.0"), + "MANDRILL_API_URL": env( + "MANDRILL_API_URL", + default="https://mandrillapp.com/api/1.0" + ), # https://anymail.readthedocs.io/en/stable/esps/mandrill/ {%- elif cookiecutter.mail_service == 'Postmark' %} "POSTMARK_SERVER_TOKEN": env("POSTMARK_SERVER_TOKEN"), - "POSTMARK_API_URL": env("POSTMARK_API_URL", default="https://api.postmarkapp.com/"), + "POSTMARK_API_URL": env( + "POSTMARK_API_URL", + default="https://api.postmarkapp.com/" + ), # https://anymail.readthedocs.io/en/stable/esps/postmark/ {%- elif cookiecutter.mail_service == 'Sendgrid' %} "SENDGRID_API_KEY": env("SENDGRID_API_KEY"), "SENDGRID_GENERATE_MESSAGE_ID": env("SENDGRID_GENERATE_MESSAGE_ID"), "SENDGRID_MERGE_FIELD_FORMAT": env("SENDGRID_MERGE_FIELD_FORMAT"), - "SENDGRID_API_URL": env("SENDGRID_API_URL", default="https://api.sendgrid.com/v3/"), + "SENDGRID_API_URL": env( + "SENDGRID_API_URL", + default="https://api.sendgrid.com/v3/" + ), # https://anymail.readthedocs.io/en/stable/esps/sendgrid/ {%- elif cookiecutter.mail_service == 'SendinBlue' %} "SENDINBLUE_API_KEY": env("SENDINBLUE_API_KEY"), - "SENDINBLUE_API_URL": env("SENDINBLUE_API_URL", default="https://api.sendinblue.com/v3/"), + "SENDINBLUE_API_URL": env( + "SENDINBLUE_API_URL", + default="https://api.sendinblue.com/v3/" + ), # https://anymail.readthedocs.io/en/stable/esps/sendinblue/ {%- elif cookiecutter.mail_service == 'SparkPost' %} "SPARKPOST_API_KEY": env("SPARKPOST_API_KEY"), - "SPARKPOST_API_URL": env("SPARKPOST_API_URL", default="https://api.sparkpost.com/api/v1"), + "SPARKPOST_API_URL": env( + "SPARKPOST_API_URL", + default="https://api.sparkpost.com/api/v1" + ), # https://anymail.readthedocs.io/en/stable/esps/sparkpost/ {%- endif %} } From 0df8cfdb901882f1bcbfba51da59450911fd4343 Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Thu, 6 Feb 2020 21:03:49 -0500 Subject: [PATCH 08/11] Added mail service pytests in test_cookiecutter_generation.py --- tests/test_cookiecutter_generation.py | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index 39b05d7c..5a569961 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -46,6 +46,41 @@ def context(): ], ids=lambda id: f"wnoise:{id[0]}-cloud:{id[1]}", ) +@pytest.mark.parametrize( + "cloud_provider,mail_service", + [ + ("AWS", "Amazon SES"), + ("AWS", "Mailgun"), + ("AWS", "Mailjet"), + ("AWS", "Mandrill"), + ("AWS", "Postmark"), + ("AWS", "Sendgrid"), + ("AWS", "SendinBlue"), + ("AWS", "SparkPost"), + ("AWS", "Plain/Vanilla Django-Anymail"), + + ("GCP", "Mailgun"), + ("GCP", "Mailjet"), + ("GCP", "Mandrill"), + ("GCP", "Postmark"), + ("GCP", "Sendgrid"), + ("GCP", "SendinBlue"), + ("GCP", "SparkPost"), + ("GCP", "Plain/Vanilla Django-Anymail"), + + ("None", "Mailgun"), + ("None", "Mailjet"), + ("None", "Mandrill"), + ("None", "Postmark"), + ("None", "Sendgrid"), + ("None", "SendinBlue"), + ("None", "SparkPost"), + ("None", "Plain/Vanilla Django-Anymail"), + + # GCP or None (i.e. no cloud provider) + Amazon SES is not supported + ], + ids=lambda id: f"cloud:{id[0]}-mail:{id[1]}", +) def context_combination( windows, use_docker, @@ -56,6 +91,7 @@ def context_combination( use_whitenoise, use_drf, cloud_provider, + mail_service, ): """Fixture that parametrize the function where it's used.""" return { @@ -68,6 +104,7 @@ def context_combination( "use_whitenoise": use_whitenoise, "use_drf": use_drf, "cloud_provider": cloud_provider, + "mail_service": mail_service, } @@ -194,3 +231,21 @@ def test_no_whitenoise_and_no_cloud_provider(cookies, context): assert result.exit_code != 0 assert isinstance(result.exception, FailedHookException) + + +def test_gcp_with_aws_ses_mail_service(cookies, context): + """It should not generate project if SES is set with GCP cloud provider""" + context.update({"cloud_provider": "GCP", "mail_service": "Amazon SES"}) + result = cookies.bake(extra_context=context) + + assert result.exit_code != 0 + assert isinstance(result.exception, FailedHookException) + + +def test_no_cloud_provider_with_aws_ses_mail_service(cookies, context): + """It should not generate project if SES is set with no cloud provider""" + context.update({"cloud_provider": "None", "mail_service": "Amazon SES"}) + result = cookies.bake(extra_context=context) + + assert result.exit_code != 0 + assert isinstance(result.exception, FailedHookException) From c839862aefded2e2f09f51afd448c8a3d015c409 Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Thu, 6 Feb 2020 22:12:30 -0500 Subject: [PATCH 09/11] Testing mail service does not raise KeyError * KeyError raised when cloud_provider was used twice in mark parametrization. * Tox isn't working properly for me (collecting 17,000 files; obviously neglecting tox.ini and/or pytest.ini) --- tests/test_cookiecutter_generation.py | 41 +++++++-------------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index 5a569961..e8b341c9 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -47,39 +47,20 @@ def context(): ids=lambda id: f"wnoise:{id[0]}-cloud:{id[1]}", ) @pytest.mark.parametrize( - "cloud_provider,mail_service", + "mail_service", [ - ("AWS", "Amazon SES"), - ("AWS", "Mailgun"), - ("AWS", "Mailjet"), - ("AWS", "Mandrill"), - ("AWS", "Postmark"), - ("AWS", "Sendgrid"), - ("AWS", "SendinBlue"), - ("AWS", "SparkPost"), - ("AWS", "Plain/Vanilla Django-Anymail"), - - ("GCP", "Mailgun"), - ("GCP", "Mailjet"), - ("GCP", "Mandrill"), - ("GCP", "Postmark"), - ("GCP", "Sendgrid"), - ("GCP", "SendinBlue"), - ("GCP", "SparkPost"), - ("GCP", "Plain/Vanilla Django-Anymail"), - - ("None", "Mailgun"), - ("None", "Mailjet"), - ("None", "Mandrill"), - ("None", "Postmark"), - ("None", "Sendgrid"), - ("None", "SendinBlue"), - ("None", "SparkPost"), - ("None", "Plain/Vanilla Django-Anymail"), - + "Amazon SES", + "Mailgun", + "MailJet", + "Mandrill", + "Postmark", + "Sendgrid", + "SendinBlue", + "SparkPost", + "Plain/Vanilla Django-Anymail" # GCP or None (i.e. no cloud provider) + Amazon SES is not supported ], - ids=lambda id: f"cloud:{id[0]}-mail:{id[1]}", + ids=lambda id: f"mail:{id[0]}", ) def context_combination( windows, From 397889050205bda8ee819200bb20920d3006b1d7 Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Sat, 14 Mar 2020 13:43:37 -0400 Subject: [PATCH 10/11] Adjusted readability * Changed Vanilla/Plain Django-Anymail to Other SMTP * Made Mailgun default again * config/production.py adjusted if conditions according to @browniebroke --- cookiecutter.json | 4 +- .../config/settings/production.py | 81 ++++++++++--------- .../requirements/production.txt | 8 +- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index 5e85af48..cfa1b346 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -34,15 +34,15 @@ "None" ], "mail_service": [ - "{% if cookiecutter.cloud_provider == 'AWS' %}Amazon SES{% else %}Plain/Vanilla Django-Anymail{% endif %}", "Mailgun", + "Amazon SES", "Mailjet", "Mandrill", "Postmark", "Sendgrid", "SendinBlue", "SparkPost", - "Plain/Vanilla Django-Anymail" + "Other SMTP" ], "use_drf": "n", "custom_bootstrap_compilation": "n", diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index e227186e..6b07141d 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -187,62 +187,58 @@ ADMIN_URL = env("DJANGO_ADMIN_URL") # ------------------------------------------------------------------------------ # https://anymail.readthedocs.io/en/stable/installation/#installing-anymail INSTALLED_APPS += ["anymail"] # noqa F405 -{%- if cookiecutter.mail_service == 'Amazon SES' %} -EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend" -{%- elif cookiecutter.mail_service == 'Mailgun' %} -EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend" -{%- elif cookiecutter.mail_service == 'Mailjet' %} -EMAIL_BACKEND = "anymail.backends.mailjet.EmailBackend" -{%- elif cookiecutter.mail_service == 'Mandrill' %} -EMAIL_BACKEND = "anymail.backends.mandrill.EmailBackend" -{%- elif cookiecutter.mail_service == 'Postmark' %} -EMAIL_BACKEND = "anymail.backends.postmark.EmailBackend" -{%- elif cookiecutter.mail_service == 'Sendgrid' %} -EMAIL_BACKEND = "anymail.backends.sendgrid.EmailBackend" -{%- elif cookiecutter.mail_service == 'SendinBlue' %} -EMAIL_BACKEND = "anymail.backends.sendinblue.EmailBackend" -{%- elif cookiecutter.mail_service == 'SparkPost' %} -EMAIL_BACKEND = "anymail.backends.sparkpost.EmailBackend" -{%- elif cookiecutter.mail_service == 'Plain/Vanilla Django-Anymail' %} -EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" -# https://docs.djangoproject.com/en/3.0/ref/settings/#email-backend -{%- endif %} +# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend # https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference +{%- if cookiecutter.mail_service == 'Mailgun' %} +# https://anymail.readthedocs.io/en/stable/esps/mailgun/ +EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend" ANYMAIL = { - # https://anymail.readthedocs.io/en/stable/esps/ - {%- if cookiecutter.mail_service == 'Amazon SES' %} - # https://anymail.readthedocs.io/en/stable/esps/amazon_ses/ - {%- elif cookiecutter.mail_service == 'Mailgun' %} "MAILGUN_API_KEY": env("MAILGUN_API_KEY"), "MAILGUN_SENDER_DOMAIN": env("MAILGUN_DOMAIN"), "MAILGUN_API_URL": env( "MAILGUN_API_URL", default="https://api.mailgun.net/v3" ), - # https://anymail.readthedocs.io/en/stable/esps/mailgun/ - {%- elif cookiecutter.mail_service == 'Mailjet' %} +} +{%- elif cookiecutter.mail_service == 'Amazon SES' %} +# https://anymail.readthedocs.io/en/stable/esps/amazon_ses/ +EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend" +ANYMAIL = {} +{%- elif cookiecutter.mail_service == 'Mailjet' %} +# https://anymail.readthedocs.io/en/stable/esps/mailjet/ +EMAIL_BACKEND = "anymail.backends.mailjet.EmailBackend" +ANYMAIL = { "MAILJET_API_KEY": env("MAILJET_API_KEY"), "MAILJET_SECRET_KEY": env("MAILJET_SECRET_KEY"), "MAILJET_API_URL": env( "MAILJET_API_URL", default="https://api.mailjet.com/v3" ), - # https://anymail.readthedocs.io/en/stable/esps/mailjet/ - {%- elif cookiecutter.mail_service == 'Mandrill' %} +} +{%- elif cookiecutter.mail_service == 'Mandrill' %} +# https://anymail.readthedocs.io/en/stable/esps/mandrill/ +EMAIL_BACKEND = "anymail.backends.mandrill.EmailBackend" +ANYMAIL = { "MANDRILL_API_KEY": env("MANDRILL_API_KEY"), "MANDRILL_API_URL": env( "MANDRILL_API_URL", default="https://mandrillapp.com/api/1.0" ), - # https://anymail.readthedocs.io/en/stable/esps/mandrill/ - {%- elif cookiecutter.mail_service == 'Postmark' %} +} +{%- elif cookiecutter.mail_service == 'Postmark' %} +# https://anymail.readthedocs.io/en/stable/esps/postmark/ +EMAIL_BACKEND = "anymail.backends.postmark.EmailBackend" +ANYMAIL = { "POSTMARK_SERVER_TOKEN": env("POSTMARK_SERVER_TOKEN"), "POSTMARK_API_URL": env( "POSTMARK_API_URL", default="https://api.postmarkapp.com/" ), - # https://anymail.readthedocs.io/en/stable/esps/postmark/ - {%- elif cookiecutter.mail_service == 'Sendgrid' %} +} +{%- elif cookiecutter.mail_service == 'Sendgrid' %} +# https://anymail.readthedocs.io/en/stable/esps/sendgrid/ +EMAIL_BACKEND = "anymail.backends.sendgrid.EmailBackend" +ANYMAIL = { "SENDGRID_API_KEY": env("SENDGRID_API_KEY"), "SENDGRID_GENERATE_MESSAGE_ID": env("SENDGRID_GENERATE_MESSAGE_ID"), "SENDGRID_MERGE_FIELD_FORMAT": env("SENDGRID_MERGE_FIELD_FORMAT"), @@ -250,23 +246,32 @@ ANYMAIL = { "SENDGRID_API_URL", default="https://api.sendgrid.com/v3/" ), - # https://anymail.readthedocs.io/en/stable/esps/sendgrid/ - {%- elif cookiecutter.mail_service == 'SendinBlue' %} +} +{%- elif cookiecutter.mail_service == 'SendinBlue' %} +# https://anymail.readthedocs.io/en/stable/esps/sendinblue/ +EMAIL_BACKEND = "anymail.backends.sendinblue.EmailBackend" +ANYMAIL = { "SENDINBLUE_API_KEY": env("SENDINBLUE_API_KEY"), "SENDINBLUE_API_URL": env( "SENDINBLUE_API_URL", default="https://api.sendinblue.com/v3/" ), - # https://anymail.readthedocs.io/en/stable/esps/sendinblue/ - {%- elif cookiecutter.mail_service == 'SparkPost' %} +} +{%- elif cookiecutter.mail_service == 'SparkPost' %} +# https://anymail.readthedocs.io/en/stable/esps/sparkpost/ +EMAIL_BACKEND = "anymail.backends.sparkpost.EmailBackend" +ANYMAIL = { "SPARKPOST_API_KEY": env("SPARKPOST_API_KEY"), "SPARKPOST_API_URL": env( "SPARKPOST_API_URL", default="https://api.sparkpost.com/api/v1" ), - # https://anymail.readthedocs.io/en/stable/esps/sparkpost/ - {%- endif %} } +{%- elif cookiecutter.mail_service == 'Other SMTP' %} +# https://anymail.readthedocs.io/en/stable/esps +EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" +ANYMAIL = {} +{%- endif %} {% if cookiecutter.use_compressor == 'y' -%} # django-compressor diff --git a/{{cookiecutter.project_slug}}/requirements/production.txt b/{{cookiecutter.project_slug}}/requirements/production.txt index 06e2a4d2..da9cbc97 100644 --- a/{{cookiecutter.project_slug}}/requirements/production.txt +++ b/{{cookiecutter.project_slug}}/requirements/production.txt @@ -18,10 +18,10 @@ django-storages[boto3]==1.9.1 # https://github.com/jschneier/django-storages {%- elif cookiecutter.cloud_provider == 'GCP' %} django-storages[google]==1.9.1 # https://github.com/jschneier/django-storages {%- endif %} -{%- if cookiecutter.mail_service == 'Amazon SES' %} -django-anymail[amazon_ses]==7.0.0 # https://github.com/anymail/django-anymail -{%- elif cookiecutter.mail_service == 'Mailgun' %} +{%- if cookiecutter.mail_service == 'Mailgun' %} django-anymail[mailgun]==7.0.0 # https://github.com/anymail/django-anymail +{%- elif cookiecutter.mail_service == 'Amazon SES' %} +django-anymail[amazon_ses]==7.0.0 # https://github.com/anymail/django-anymail {%- elif cookiecutter.mail_service == 'Mailjet' %} django-anymail[mailjet]==7.0.0 # https://github.com/anymail/django-anymail {%- elif cookiecutter.mail_service == 'Mandrill' %} @@ -34,6 +34,6 @@ django-anymail[sendgrid]==7.0.0 # https://github.com/anymail/django-anymail django-anymail[sendinblue]==7.0.0 # https://github.com/anymail/django-anymail {%- elif cookiecutter.mail_service == 'SparkPost' %} django-anymail[sparkpost]==7.0.0 # https://github.com/anymail/django-anymail -{%- elif cookiecutter.mail_service == 'Plain/Vanilla Django-Anymail' %} +{%- elif cookiecutter.mail_service == 'Other SMTP' %} django-anymail==7.0.0 # https://github.com/anymail/django-anymail {%- endif %} From 5e1d1dd1c39b92bae280ae071b3e20cad1c88ae2 Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Sat, 14 Mar 2020 15:09:05 -0400 Subject: [PATCH 11/11] Fixed tests for mail providers --- tests/test_cookiecutter_generation.py | 20 ++++++------- .../config/settings/production.py | 29 +++++-------------- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index d4db1085..91f44ae5 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -48,6 +48,15 @@ SUPPORTED_COMBINATIONS = [ {"cloud_provider": "GCP", "use_whitenoise": "n"}, {"cloud_provider": "None", "use_whitenoise": "y"}, # Note: cloud_provider=None AND use_whitenoise=n is not supported + {"mail_service": "Mailgun"}, + {"mail_service": "Amazon SES"}, + {"mail_service": "Mailjet"}, + {"mail_service": "Mandrill"}, + {"mail_service": "Postmark"}, + {"mail_service": "Sendgrid"}, + {"mail_service": "SendinBlue"}, + {"mail_service": "SparkPost"}, + {"mail_service": "Other SMTP"}, {"use_drf": "y"}, {"use_drf": "n"}, {"js_task_runner": "None"}, @@ -73,21 +82,10 @@ SUPPORTED_COMBINATIONS = [ {"keep_local_envs_in_vcs": "n"}, {"debug": "y"}, {"debug": "n"}, - {"mail_service", "AWS SES"}, - {"mail_service", "Mailgun"}, - {"mail_service", "Mailjet"}, - {"mail_service", "Mandrill"}, - {"mail_service", "Postmark"}, - {"mail_service", "Sendgrid"}, - {"mail_service", "SendinBlue"}, - {"mail_service", "SparkPost"}, - {"mail_service", "Other SMTP"}, ] UNSUPPORTED_COMBINATIONS = [ {"cloud_provider": "None", "use_whitenoise": "n"}, - {"cloud_provider": "GCP", "mail_service": "Amazon SES"}, - {"cloud_provider": "None", "mail_service": "Amazon SES"} ] diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 6b07141d..13e8c697 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -195,10 +195,7 @@ EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend" ANYMAIL = { "MAILGUN_API_KEY": env("MAILGUN_API_KEY"), "MAILGUN_SENDER_DOMAIN": env("MAILGUN_DOMAIN"), - "MAILGUN_API_URL": env( - "MAILGUN_API_URL", - default="https://api.mailgun.net/v3" - ), + "MAILGUN_API_URL": env("MAILGUN_API_URL", default="https://api.mailgun.net/v3"), } {%- elif cookiecutter.mail_service == 'Amazon SES' %} # https://anymail.readthedocs.io/en/stable/esps/amazon_ses/ @@ -210,10 +207,7 @@ EMAIL_BACKEND = "anymail.backends.mailjet.EmailBackend" ANYMAIL = { "MAILJET_API_KEY": env("MAILJET_API_KEY"), "MAILJET_SECRET_KEY": env("MAILJET_SECRET_KEY"), - "MAILJET_API_URL": env( - "MAILJET_API_URL", - default="https://api.mailjet.com/v3" - ), + "MAILJET_API_URL": env("MAILJET_API_URL", default="https://api.mailjet.com/v3"), } {%- elif cookiecutter.mail_service == 'Mandrill' %} # https://anymail.readthedocs.io/en/stable/esps/mandrill/ @@ -221,8 +215,7 @@ EMAIL_BACKEND = "anymail.backends.mandrill.EmailBackend" ANYMAIL = { "MANDRILL_API_KEY": env("MANDRILL_API_KEY"), "MANDRILL_API_URL": env( - "MANDRILL_API_URL", - default="https://mandrillapp.com/api/1.0" + "MANDRILL_API_URL", default="https://mandrillapp.com/api/1.0" ), } {%- elif cookiecutter.mail_service == 'Postmark' %} @@ -230,10 +223,7 @@ ANYMAIL = { EMAIL_BACKEND = "anymail.backends.postmark.EmailBackend" ANYMAIL = { "POSTMARK_SERVER_TOKEN": env("POSTMARK_SERVER_TOKEN"), - "POSTMARK_API_URL": env( - "POSTMARK_API_URL", - default="https://api.postmarkapp.com/" - ), + "POSTMARK_API_URL": env("POSTMARK_API_URL", default="https://api.postmarkapp.com/"), } {%- elif cookiecutter.mail_service == 'Sendgrid' %} # https://anymail.readthedocs.io/en/stable/esps/sendgrid/ @@ -242,10 +232,7 @@ ANYMAIL = { "SENDGRID_API_KEY": env("SENDGRID_API_KEY"), "SENDGRID_GENERATE_MESSAGE_ID": env("SENDGRID_GENERATE_MESSAGE_ID"), "SENDGRID_MERGE_FIELD_FORMAT": env("SENDGRID_MERGE_FIELD_FORMAT"), - "SENDGRID_API_URL": env( - "SENDGRID_API_URL", - default="https://api.sendgrid.com/v3/" - ), + "SENDGRID_API_URL": env("SENDGRID_API_URL", default="https://api.sendgrid.com/v3/"), } {%- elif cookiecutter.mail_service == 'SendinBlue' %} # https://anymail.readthedocs.io/en/stable/esps/sendinblue/ @@ -253,8 +240,7 @@ EMAIL_BACKEND = "anymail.backends.sendinblue.EmailBackend" ANYMAIL = { "SENDINBLUE_API_KEY": env("SENDINBLUE_API_KEY"), "SENDINBLUE_API_URL": env( - "SENDINBLUE_API_URL", - default="https://api.sendinblue.com/v3/" + "SENDINBLUE_API_URL", default="https://api.sendinblue.com/v3/" ), } {%- elif cookiecutter.mail_service == 'SparkPost' %} @@ -263,8 +249,7 @@ EMAIL_BACKEND = "anymail.backends.sparkpost.EmailBackend" ANYMAIL = { "SPARKPOST_API_KEY": env("SPARKPOST_API_KEY"), "SPARKPOST_API_URL": env( - "SPARKPOST_API_URL", - default="https://api.sparkpost.com/api/v1" + "SPARKPOST_API_URL", default="https://api.sparkpost.com/api/v1" ), } {%- elif cookiecutter.mail_service == 'Other SMTP' %}