Changeset - 8e77c75bd65a
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 14 years ago 2011-10-21 13:28:32
marcin@python-works.com
made auth type optional in constructor
1 file changed with 7 insertions and 7 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/smtp_mailer.py
Show inline comments
 
@@ -33,28 +33,27 @@ from email.mime.audio import MIMEAudio
 
from email.mime.base import MIMEBase
 
from email.mime.text import MIMEText
 
from email.utils import formatdate
 
from email import encoders
 

	
 

	
 

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

	
 
    mailer = SmtpMailer(mail_from, user, passwd, mail_server,
 
    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
 
    :param attachment_files is a dict of {filename:location}
 
        it tries to guess the mimetype and attach the file
 

	
 
    """
 

	
 
    def __init__(self, mail_from, user, passwd, mail_server,smtp_auth,
 
                    mail_port=None, ssl=False, tls=False, debug=False):
 
    def __init__(self, mail_from, user, passwd, mail_server, smtp_auth=None,
 
                 mail_port=None, ssl=False, tls=False, debug=False):
 

	
 
        self.mail_from = mail_from
 
        self.mail_server = mail_server
 
        self.mail_port = mail_port
 
        self.user = user
 
        self.passwd = passwd
 
@@ -80,14 +79,14 @@ class SmtpMailer(object):
 
            smtp_serv.set_debuglevel(1)
 

	
 
        smtp_serv.ehlo()
 
        if self.auth:
 
            smtp_serv.esmtp_features["auth"] = self.auth
 

	
 
        #if server requires authorization you must provide login and password
 
        #but only if we have them
 
        # 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)
 

	
 
        date_ = formatdate(localtime=True)
 
        msg = MIMEMultipart()
 
        msg.set_type('multipart/alternative')
 
@@ -157,9 +156,10 @@ class SmtpMailer(object):
 

	
 
        :param msg_file:
 
        """
 
        if isinstance(msg_file, str):
 
            return open(msg_file, "rb").read()
 
        else:
 
            #just for safe seek to 0
 
            # just for safe seek to 0
 
            msg_file.seek(0)
 
            return msg_file.read()
 

	
0 comments (0 inline, 0 general)