From ef8a77f7476490d02e01d4c9c1b82a78b4ae8a83 Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Wed, 18 Dec 2019 10:04:49 -0500 Subject: [PATCH 1/4] Enable configuring email backend via environment --- app/app/settings.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/app/settings.py b/app/app/settings.py index c871ff5b..195c65e9 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -296,12 +296,12 @@ APPLICATION_INSIGHTS = { 'endpoint': env('AZURE_APPINSIGHTS_ENDPOINT', None), } -## necessary for email verification setup -# EMAIL_USE_TLS = True -# EMAIL_HOST = 'smtp.gmail.com' -# EMAIL_HOST_USER = 'random@gmail.com' -# EMAIL_HOST_PASSWORD = 'gfds6jk#4ljIr%G8%' -# EMAIL_PORT = 587 -# -## During development only -# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +# necessary for email verification of new accounts +EMAIL_USE_TLS = env.bool('EMAIL_USE_TLS', False) +EMAIL_HOST = env('EMAIL_HOST', None) +EMAIL_HOST_USER = env('EMAIL_HOST_USER', None) +EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD', None) +EMAIL_PORT = env.int('EMAIL_PORT', 587) + +if not EMAIL_HOST: + EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' From 59b9d147e5b5f479663ce224df320f3b2a24b20c Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Wed, 18 Dec 2019 10:05:14 -0500 Subject: [PATCH 2/4] Add Sendgrid email backend to Azure deployment --- azuredeploy.json | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/azuredeploy.json b/azuredeploy.json index 7412346a..1f16cfcc 100644 --- a/azuredeploy.json +++ b/azuredeploy.json @@ -33,6 +33,7 @@ "adminPassword": { "type": "securestring", "minLength": 16, + "maxLength": 50, "metadata": { "description": "The password for the admin account." } @@ -52,6 +53,21 @@ "description": "The SKU of the webapp hosting tier." } }, + "sendgridSku": { + "type": "string", + "defaultValue": "free", + "allowedValues": [ + "free", + "bronze", + "silver", + "gold", + "platinum", + "premier" + ], + "metadata": { + "description": "The SKU of the Sendgrid email account." + } + }, "databaseCores": { "type": "int", "defaultValue": 2, @@ -124,11 +140,29 @@ "databaseUserCredentials" : "[concat(uriComponent(concat(parameters('adminUserName'), '@', variables('databaseServerName'))), ':', parameters('adminPassword'))]", "databaseFqdn" : "[concat( variables('databaseServerName'), '.postgres.database.azure.com:', variables('databaseServerPort'))]", "databaseConnectionString": "[concat('pgsql://', variables('databaseUserCredentials'), '@', variables('databaseFqdn'), '/', parameters('databaseName'))]", + "sendgridAccountName": "[concat(parameters('appName'),'-email')]", "appServicePlanName": "[concat(parameters('appName'),'-hosting')]", "analyticsName": "[concat(parameters('appName'),'-analytics')]", "appFqdn": "[concat(parameters('appName'),'.azurewebsites.net')]" }, "resources": [ + { + "name": "[variables('sendgridAccountName')]", + "type": "Sendgrid.Email/accounts", + "apiVersion": "2015-01-01", + "location": "[variables('location')]", + "plan": { + "name": "[parameters('sendgridSku')]", + "publisher": "Sendgrid", + "product": "sendgrid_azure", + "promotionCode": "" + }, + "properties": { + "acceptMarketingEmails": false, + "email": "[parameters('adminContactEmail')]", + "password": "[parameters('adminPassword')]" + } + }, { "type": "Microsoft.Insights/components", "apiVersion": "2015-05-01", @@ -207,6 +241,7 @@ "kind": "app,linux,container", "location": "[variables('location')]", "dependsOn": [ + "[resourceId('Sendgrid.Email/accounts', variables('sendgridAccountName'))]", "[resourceId('Microsoft.DBforPostgreSQL/servers/', variables('databaseServerName'))]", "[resourceId('Microsoft.Insights/components', variables('analyticsName'))]", "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]" @@ -261,6 +296,26 @@ "name": "ADMIN_PASSWORD", "value": "[parameters('adminPassword')]" }, + { + "name": "EMAIL_USE_TLS", + "value": "True" + }, + { + "name": "EMAIL_HOST", + "value": "[reference(resourceId('Sendgrid.Email/accounts', variables('sendgridAccountName'))).smtpServer]" + }, + { + "name": "EMAIL_HOST_USER", + "value": "[reference(resourceId('Sendgrid.Email/accounts', variables('sendgridAccountName'))).username]" + }, + { + "name": "EMAIL_HOST_PASSWORD", + "value": "[parameters('adminPassword')]" + }, + { + "name": "EMAIL_PORT", + "value": "587" + }, { "name": "DEBUG", "value": "False" From 945a712d23bbfcd1617928eca31ce3ab8bb127d9 Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Wed, 18 Dec 2019 10:18:47 -0500 Subject: [PATCH 3/4] Fix hard-coded scheme in account activation email --- app/authentification/templates/acc_active_email.html | 2 +- app/authentification/views.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/authentification/templates/acc_active_email.html b/app/authentification/templates/acc_active_email.html index 4c7be2db..61d99bdd 100644 --- a/app/authentification/templates/acc_active_email.html +++ b/app/authentification/templates/acc_active_email.html @@ -1,5 +1,5 @@ {% autoescape off %} Hi {{ user.username }}, Please click on the link to confirm your email, -http://{{ domain }}{% url 'activate' uidb64=uid token=token %} +{{ scheme }}://{{ domain }}{% url 'activate' uidb64=uid token=token %} {% endautoescape %} diff --git a/app/authentification/views.py b/app/authentification/views.py index d57df650..d53cbafa 100644 --- a/app/authentification/views.py +++ b/app/authentification/views.py @@ -39,6 +39,7 @@ class SignupView(TemplateView): message = render_to_string('acc_active_email.html', { 'user': user, 'domain': current_site.domain, + 'scheme': request.scheme, 'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(), 'token': account_activation_token.make_token(user), }) From dc2e26410834f0cafc7c3f60dfe929dfbc55105e Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Wed, 18 Dec 2019 10:19:31 -0500 Subject: [PATCH 4/4] Make activation instructions more explicit --- app/authentification/templates/acc_active_email.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/authentification/templates/acc_active_email.html b/app/authentification/templates/acc_active_email.html index 61d99bdd..c5d9ca70 100644 --- a/app/authentification/templates/acc_active_email.html +++ b/app/authentification/templates/acc_active_email.html @@ -1,5 +1,5 @@ {% autoescape off %} Hi {{ user.username }}, -Please click on the link to confirm your email, +Please click on the link to confirm your email and activate your Doccano account: {{ scheme }}://{{ domain }}{% url 'activate' uidb64=uid token=token %} {% endautoescape %}