From 62e142de17e66ce413763b94e341095952a32edc Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 17 2017 10:09:11 +0000 Subject: Only connect to the smtp server if we're going to send an email Otherwise, we keep on going and we will print the email in the logs as we do. --- diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py index 3fb0e69..df3d971 100644 --- a/pagure/lib/notify.py +++ b/pagure/lib/notify.py @@ -218,12 +218,16 @@ def send_email(text, subject, to_mail, else: subject_tag = 'Pagure' - if pagure.APP.config['SMTP_SSL']: - smtp = smtplib.SMTP_SSL( - pagure.APP.config['SMTP_SERVER'], pagure.APP.config['SMTP_PORT']) - else: - smtp = smtplib.SMTP( - pagure.APP.config['SMTP_SERVER'], pagure.APP.config['SMTP_PORT']) + smtp = None + if pagure.APP.config.get('EMAIL_SEND', True): + if pagure.APP.config['SMTP_SSL']: + smtp = smtplib.SMTP_SSL( + pagure.APP.config['SMTP_SERVER'], + pagure.APP.config['SMTP_PORT']) + else: + smtp = smtplib.SMTP( + pagure.APP.config['SMTP_SERVER'], + pagure.APP.config['SMTP_PORT']) for mailto in to_mail.split(','): msg = MIMEText(text.encode('utf-8'), 'plain', 'utf-8')