aboutsummaryrefslogtreecommitdiff
path: root/src/notifications/emails.py
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2017-06-17 22:36:44 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2017-06-17 22:36:44 +0200
commit2e695a4331430050465c4e8b892768af5e18e934 (patch)
treef9ef9a04b8b76433e70db1cd1e75e47949662095 /src/notifications/emails.py
parentUpdated translations. (diff)
downloadnewspipe-2e695a4331430050465c4e8b892768af5e18e934.tar.gz
newspipe-2e695a4331430050465c4e8b892768af5e18e934.tar.bz2
newspipe-2e695a4331430050465c4e8b892768af5e18e934.zip
The Postmark team has chosen not to continue development of the Heroku Add-on as of June 30, 2017. Newspipe is now using SendGrid when deployed on Heroku.
Diffstat (limited to 'src/notifications/emails.py')
-rw-r--r--src/notifications/emails.py35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/notifications/emails.py b/src/notifications/emails.py
index 479d43cf..ebf301ef 100644
--- a/src/notifications/emails.py
+++ b/src/notifications/emails.py
@@ -24,7 +24,8 @@ import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
-from postmark import PMMail
+import sendgrid
+from sendgrid.helpers.mail import *
import conf
from web.decorators import async
@@ -45,11 +46,11 @@ def send_async_email(mfrom, mto, msg):
def send(*args, **kwargs):
"""
- This functions enables to send email through Postmark
+ This functions enables to send email through SendGrid
or a SMTP server.
"""
if conf.ON_HEROKU:
- send_postmark(**kwargs)
+ send_sendgrid(**kwargs)
else:
send_smtp(**kwargs)
@@ -83,11 +84,16 @@ def send_smtp(to="", bcc="", subject="", plaintext="", html=""):
s.sendmail(conf.NOTIFICATION_EMAIL, msg['To'] + ", " + msg['BCC'], msg.as_string())
s.quit()
+
def send_postmark(to="", bcc="", subject="", plaintext=""):
"""
Send an email via Postmark. Used when the application is deployed on
Heroku.
+ Note: The Postmark team has chosen not to continue development of this
+ Heroku add-on as of June 30, 2017. Newspipe is now using SendGrid when
+ deployed on Heroku.
"""
+ from postmark import PMMail
try:
message = PMMail(api_key = conf.POSTMARK_API_KEY,
subject = subject,
@@ -98,5 +104,26 @@ def send_postmark(to="", bcc="", subject="", plaintext=""):
message.bcc = bcc
message.send()
except Exception as e:
- logger.exception("send_postmark raised:")
+ logger.exception('send_postmark raised:')
raise e
+
+
+def send_sendgrid(to="", bcc="", subject="", plaintext=""):
+ """
+ Send an email via SendGrid. Used when the application is deployed on
+ Heroku.
+ """
+ sg = sendgrid.SendGridAPIClient(apikey=conf.SENDGRID_API_KEY)
+ from_email = Email(conf.NOTIFICATION_EMAIL)
+ subject = subject
+ to_email = Email(to)
+ content = Content('text/plain', plaintext)
+ mail = Mail(from_email, subject, to_email, content)
+ if bcc != "":
+ personalization = Personalization()
+ personalization.add_bcc(Email(bcc))
+ mail.add_personalization(personalization)
+ response = sg.client.mail.send.post(request_body=mail.get())
+ # print(response.status_code)
+ # print(response.body)
+ # print(response.headers)
bgstack15