From c8eb5462eb921313d3fbb9a9957125022d444cd3 Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Thu, 6 Feb 2020 16:58:15 -0500 Subject: [PATCH] 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 %}