Changeset - 3009a239199d
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2019-07-21 23:34:47
mads@kiilerich.com
smtp_mailer: clarify that sslerror is ssl.SSLError - slightly clearer, and Python 3 compatible
1 file changed with 4 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/rcmail/smtp_mailer.py
Show inline comments
 
@@ -19,26 +19,27 @@ Simple smtp mailer used in Kallithea
 

	
 
This file was forked by the Kallithea project in July 2014.
 
Original author and date, and relevant copyright and licensing information is below:
 
:created_on: Sep 13, 2010
 
:author: marcink
 
:copyright: (c) 2013 RhodeCode GmbH, and others.
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 

	
 
import time
 
import logging
 
import smtplib
 
from socket import sslerror
 
from ssl import SSLError
 
from email.utils import formatdate
 

	
 
from kallithea.lib.rcmail.message import Message
 
from kallithea.lib.rcmail.utils import DNS_NAME
 

	
 

	
 
class SmtpMailer(object):
 
    """SMTP mailer class
 

	
 
    mailer = SmtpMailer(mail_from, user, passwd, mail_server, smtp_auth
 
                        mail_port, ssl, tls)
 
    mailer.send(recipients, subject, body, attachment_files)
 

	
 
    :param recipients might be a list of string or single string
 
@@ -91,15 +92,15 @@ class SmtpMailer(object):
 
            smtp_serv.esmtp_features["auth"] = self.auth
 

	
 
        # if server requires authorization you must provide login and password
 
        # but only if we have them
 
        if self.user and self.passwd:
 
            smtp_serv.login(self.user, self.passwd)
 

	
 
        smtp_serv.sendmail(msg.sender, msg.send_to, raw_msg.as_string())
 
        logging.info('MAIL SENT TO: %s' % recipients)
 

	
 
        try:
 
            smtp_serv.quit()
 
        except sslerror:
 
            # sslerror is raised in tls connections on closing sometimes
 
        except SSLError:
 
            # SSL error might sometimes be raised in tls connections on closing
 
            smtp_serv.close()
0 comments (0 inline, 0 general)