From c7f424cab9fbb5fcd02d5a9d6f468511e2a5cc1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thales=20C=C3=A9sar?= Date: Sat, 3 Oct 2020 13:23:50 -0300 Subject: [PATCH 1/2] Add From email env var for SendGrid --- README.md | 1 + legislei/send_reports.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c5e3b99..d98e447 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ A seguir, acesse a pasta raíz do projeto e crie o arquivo `.env` dentro da past | EMAIL_SSL | `True` se o server SMTP trabalha com SSL | | EMAIL_TLS | `True` se o server SMTP trabalha com TLS | | EMAIL_USR | Endereço de email do gmail para envio de relatórios | +| EMAIL_FROM_EMAIL | Endereço de email do gmail para para o campo From | | EMAIL_PSW | Senha do email do gmail para envio de relatórios | | FIREBASE_API_TOKEN | Token da API REST legada do Firebase para envio de Push Notifications | | PORT | Porta para expor a aplicação Flask | diff --git a/legislei/send_reports.py b/legislei/send_reports.py index 3040de0..2b77fe1 100644 --- a/legislei/send_reports.py +++ b/legislei/send_reports.py @@ -16,7 +16,8 @@ smtp_server = os.environ.get("EMAIL_ENDPOINT", "smtp.gmail.com") smtp_server_port = os.environ.get("EMAIL_PORT", "587") -from_email = os.environ.get("EMAIL_USR", None) +email_user = os.environ.get("EMAIL_USR", None) +from_email = os.environ.get("EMAIL_FROM_EMAIL", email_user) password = os.environ.get("EMAIL_PSW", None) uses_ssl = os.environ.get("EMAIL_SSL", "False") in ['True', 'true'] uses_tls = os.environ.get("EMAIL_TLS", "True") in ['True', 'true'] @@ -49,7 +50,7 @@ def send_email(email, reports, dates): s = smtplib.SMTP(smtp_server, int(smtp_server_port)) if uses_tls: s.starttls() - s.login(from_email, password) + s.login(email_user, password) msg = MIMEText(html_report, 'html', 'utf-8') msg['Subject'] = Header(u'🇧🇷 Relatório de parlamentares', 'utf-8') msg['From'] = 'Legislei <{}>'.format(from_email) From 67c7c8649989af93d1faf7abb5fb411c909c7c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thales=20C=C3=A9sar?= Date: Sat, 3 Oct 2020 13:29:16 -0300 Subject: [PATCH 2/2] Update app.json with new env var --- app.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.json b/app.json index ba1d7fa..29c252b 100644 --- a/app.json +++ b/app.json @@ -27,6 +27,9 @@ "EMAIL_USR": { "required": true }, + "EMAIL_FROM_EMAIL": { + "required": true + }, "FIREBASE_API_TOKEN": { "required": true },