python类SMTPException()的实例源码

smtpd.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _deliver(self, mailfrom, rcpttos, data):
        import smtplib
        refused = {}
        try:
            s = smtplib.SMTP()
            s.connect(self._remoteaddr[0], self._remoteaddr[1])
            try:
                refused = s.sendmail(mailfrom, rcpttos, data)
            finally:
                s.quit()
        except smtplib.SMTPRecipientsRefused, e:
            print >> DEBUGSTREAM, 'got SMTPRecipientsRefused'
            refused = e.recipients
        except (socket.error, smtplib.SMTPException), e:
            print >> DEBUGSTREAM, 'got', e.__class__
            # All recipients were refused.  If the exception had an associated
            # error code, use it.  Otherwise,fake it with a non-triggering
            # exception code.
            errcode = getattr(e, 'smtp_code', -1)
            errmsg = getattr(e, 'smtp_error', 'ignore')
            for r in rcpttos:
                refused[r] = (errcode, errmsg)
        return refused
FortiMail.py 文件源码 项目:ips-alert 作者: farcompen 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def mail(self):

        gonderen = "sender e-mail"
        pswd = "sender e-mail passwd"
        alici = "receiver e mail "
        cc = "if you need add cc e-mail "
        body=self.mesaj
        print(self.mesaj)
        try:
            server = smtplib.SMTP("smtp.live.com", 587)
            server.starttls()
            server.login(gonderen, pswd)
            server.sendmail(gonderen,[alici,cc],body)
            server.close()
            print("mail gönderildi")
        except smtplib.SMTPException as e:
            print(str(e))
PySMS.py 文件源码 项目:PySMS 作者: clayshieh 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def init_server(self):
        self.logger.info("Initializing SMTP/IMAP servers.")
        # PySMS at minimum uses smtp server
        try:
            if self.ssl:
                self.smtp = smtplib.SMTP_SSL(self.smtp_server, self.smtp_port)
            else:
                self.smtp = smtplib.SMTP(self.smtp_server, self.smtp_port)
                self.smtp.starttls()
            self.smtp.login(self.address, self.password)
        except smtplib.SMTPException:
            raise PySMSException("Unable to start smtp server, please check credentials.")

        # If responding functionality is enabled
        if self.imap_server:
            try:
                if self.ssl:
                    self.imap = imaplib.IMAP4_SSL(self.imap_server)
                else:
                    self.imap = imaplib.IMAP4(self.imap_server)
                r, data = self.imap.login(self.address, self.password)
                if r == "OK":
                    r, data = self.imap.select(self.imap_mailbox)
                    if r != "OK":
                        raise PySMSException("Unable to select mailbox: {0}".format(self.imap_mailbox))
                else:
                    raise PySMSException("Unable to login to IMAP server with given credentials.")
            except imaplib.IMAP4.error:
                raise PySMSException("Unable to start IMAP server, please check address and SSL/TLS settings.")
smtpd.py 文件源码 项目:darkc0de-old-stuff 作者: tuwid 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _deliver(self, mailfrom, rcpttos, data):
        import smtplib
        refused = {}
        try:
            s = smtplib.SMTP()
            s.connect(self._remoteaddr[0], self._remoteaddr[1])
            try:
                refused = s.sendmail(mailfrom, rcpttos, data)
            finally:
                s.quit()
        except smtplib.SMTPRecipientsRefused, e:
            print >> DEBUGSTREAM, 'got SMTPRecipientsRefused'
            refused = e.recipients
        except (socket.error, smtplib.SMTPException), e:
            print >> DEBUGSTREAM, 'got', e.__class__
            # All recipients were refused.  If the exception had an associated
            # error code, use it.  Otherwise,fake it with a non-triggering
            # exception code.
            errcode = getattr(e, 'smtp_code', -1)
            errmsg = getattr(e, 'smtp_error', 'ignore')
            for r in rcpttos:
                refused[r] = (errcode, errmsg)
        return refused
darkSMTPv.py 文件源码 项目:darkc0de-old-stuff 作者: tuwid 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def sendchk(listindex, host, user, password):   # seperated function for checking
    try:
        smtp = smtplib.SMTP(host)
        smtp.login(user, password)
        code = smtp.ehlo()[0]
        if not (200 <= code <= 299):
            code = smtp.helo()[0]
            if not (200 <= code <= 299):
                raise SMTPHeloError(code, resp)
        smtp.sendmail(fromaddr, toaddr, message)
        print "\n\t[!] Email Sent Successfully:",host, user, password
        print "\t[!] Message Sent Successfully\n"
        LSstring = host+":"+user+":"+password+"\n"
        nList.append(LSstring)      # special list for AMS file ID's
        LFile = open(output, "a")
        LFile.write(LSstring)       # save working host/usr/pass to file
        LFile.close()
        AMSout = open("AMSlist.txt", "a")
        AMSout.write("[Server"+str(nList.index(LSstring))+"]\nName="+str(host)+"\nPort=25\nUserID=User\nBccSize=50\nUserName="+str(user)+"\nPassword="+str(password)+"\nAuthType=0\n\n")
        smtp.quit()
    except(socket.gaierror, socket.error, socket.herror, smtplib.SMTPException), msg:
        print "[-] Login Failed:", host, user, password
        pass
mailer.py 文件源码 项目:abusehelper 作者: Exploit-install 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def starttls(self, keyfile=None, certfile=None):
        self.ehlo_or_helo_if_needed()
        if not self.has_extn("starttls"):
            raise smtplib.SMTPException("server doesn't support STARTTLS")

        response, reply = self.docmd("STARTTLS")
        if response == 220:
            with ca_certs(self._ca_certs) as certs:
                self.sock = ssl.wrap_socket(
                    self.sock,
                    certfile=certfile,
                    keyfile=keyfile,
                    ca_certs=certs,
                    cert_reqs=ssl.CERT_REQUIRED
                )
            cert = self.sock.getpeercert()
            match_hostname(cert, self._host)

            self.file = smtplib.SSLFakeFile(self.sock)
            self.helo_resp = None
            self.ehlo_resp = None
            self.esmtp_features = {}
            self.does_esmtp = 0
        return response, reply
mailer.py 文件源码 项目:abusehelper 作者: Exploit-install 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _connect(self, host, port, retry_interval=60.0):
        server = None

        while server is None:
            self.log.info(u"Connecting to SMTP server {0!r} port {1}".format(host, port))
            try:
                server = yield idiokit.thread(
                    SMTP, host, port,
                    ca_certs=self.smtp_ca_certs,
                    timeout=self.smtp_connection_timeout
                )
            except (socket.error, smtplib.SMTPException) as exc:
                self.log.error(u"Failed connecting to SMTP server: {0}".format(utils.format_exception(exc)))
            else:
                self.log.info(u"Connected to the SMTP server")
                break

            self.log.info(u"Retrying SMTP connection in {0:.2f} seconds".format(retry_interval))
            yield idiokit.sleep(retry_interval)

        idiokit.stop(server)
smtp.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def close(self):
        """Closes the connection to the email server."""
        if self.connection is None:
            return
        try:
            try:
                self.connection.quit()
            except (ssl.SSLError, smtplib.SMTPServerDisconnected):
                # This happens when calling quit() on a TLS connection
                # sometimes, or when the connection was already disconnected
                # by the server.
                self.connection.close()
            except smtplib.SMTPException:
                if self.fail_silently:
                    return
                raise
        finally:
            self.connection = None
smtp.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def close(self):
        """Closes the connection to the email server."""
        if self.connection is None:
            return
        try:
            try:
                self.connection.quit()
            except (ssl.SSLError, smtplib.SMTPServerDisconnected):
                # This happens when calling quit() on a TLS connection
                # sometimes, or when the connection was already disconnected
                # by the server.
                self.connection.close()
            except smtplib.SMTPException:
                if self.fail_silently:
                    return
                raise
        finally:
            self.connection = None
utils.py 文件源码 项目:PyBackup 作者: FRReinert 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def send(self, subject, message):
        '''
        Send email to mailing list
        '''

        smtp = self.connect()

        header  = 'from: %s\n' % self.mail_address
        header += 'to: %s\n' % ','.join(self.mailing_list)
        header += 'subject: %s\n' % subject
        message = header + '\r\n\r\n' + message

        try:
            smtp.sendmail(self.mail_address, self.mailing_list, message)
            smtp.quit()

        except SMTPException as e:
            print ("Could not send the emails: %s" % e)
smtpd.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def _deliver(self, mailfrom, rcpttos, data):
        import smtplib
        refused = {}
        try:
            s = smtplib.SMTP()
            s.connect(self._remoteaddr[0], self._remoteaddr[1])
            try:
                refused = s.sendmail(mailfrom, rcpttos, data)
            finally:
                s.quit()
        except smtplib.SMTPRecipientsRefused, e:
            print >> DEBUGSTREAM, 'got SMTPRecipientsRefused'
            refused = e.recipients
        except (socket.error, smtplib.SMTPException), e:
            print >> DEBUGSTREAM, 'got', e.__class__
            # All recipients were refused.  If the exception had an associated
            # error code, use it.  Otherwise,fake it with a non-triggering
            # exception code.
            errcode = getattr(e, 'smtp_code', -1)
            errmsg = getattr(e, 'smtp_error', 'ignore')
            for r in rcpttos:
                refused[r] = (errcode, errmsg)
        return refused
FortiMail.py 文件源码 项目:Fortigate-Traffic-Alert 作者: farcompen 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def mail(self):

        gonderen = "sender e-mail"
        pswd = "sender e-mail passwd"
        alici = "receiver e mail "
        cc = "if you need add cc e-mail "
        body=self.mesaj
        print(self.mesaj)
        try:
            server = smtplib.SMTP("smtp.live.com", 587)
            server.starttls()
            server.login(gonderen, pswd)
            server.sendmail(gonderen,[alici,cc],body)
            server.close()
            print("mail gönderildi")
        except smtplib.SMTPException as e:
            print(str(e))
backup.py 文件源码 项目:backuper 作者: antirek 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _send_mime_text_to_email(self, text, email):
        """

        :type text: mime_text.MIMEText
        :type email: str
        :return:
        """
        text['To'] = email
        try:
            pass
            connection = smtplib.SMTP(self._smtp_config['host'])
            connection.ehlo()
            connection.starttls()
            connection.ehlo()
            connection.login(self._smtp_config['username'], self._smtp_config['password'])
            connection.sendmail(self._smtp_config['sender'], email, text.as_string())
            connection.quit()
        except smtplib.SMTPException:
            self._logger.exception('Unable to send email to address "{}"'.format(email))
smtp.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def close(self):
        """Closes the connection to the email server."""
        if self.connection is None:
            return
        try:
            try:
                self.connection.quit()
            except (ssl.SSLError, smtplib.SMTPServerDisconnected):
                # This happens when calling quit() on a TLS connection
                # sometimes, or when the connection was already disconnected
                # by the server.
                self.connection.close()
            except smtplib.SMTPException:
                if self.fail_silently:
                    return
                raise
        finally:
            self.connection = None
message_users.py 文件源码 项目:30-Days-of-Python 作者: codingforentrepreneurs 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def send_email(self):
        self.make_messages()
        if len(self.email_messages) > 0:
            for detail in self.email_messages:
                user_email = detail['email']
                user_message = detail['message']
                try:
                    email_conn = smtplib.SMTP(host, port)
                    email_conn.ehlo()
                    email_conn.starttls()
                    email_conn.login(username, password)
                    the_msg = MIMEMultipart("alternative")
                    the_msg['Subject'] = "Billing Update!"
                    the_msg["From"] = from_email
                    the_msg["To"]  = user_email
                    part_1 = MIMEText(user_message, 'plain')
                    the_msg.attach(part_1)
                    email_conn.sendmail(from_email, [user_email], the_msg.as_string())
                    email_conn.quit()
                except smtplib.SMTPException:
                    print("error sending message")
            return True
        return False
day_12_end.py 文件源码 项目:30-Days-of-Python 作者: codingforentrepreneurs 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def send_email(self):
        self.make_messages()
        if len(self.email_messages) > 0:
            for detail in self.email_messages:
                user_email = detail['email']
                user_message = detail['message']
                try:
                    email_conn = smtplib.SMTP(host, port)
                    email_conn.ehlo()
                    email_conn.starttls()
                    email_conn.login(username, password)
                    the_msg = MIMEMultipart("alternative")
                    the_msg['Subject'] = "Billing Update!"
                    the_msg["From"] = from_email
                    the_msg["To"]  = user_email
                    part_1 = MIMEText(user_message, 'plain')
                    the_msg.attach(part_1)
                    email_conn.sendmail(from_email, [user_email], the_msg.as_string())
                    email_conn.quit()
                except smtplib.SMTPException:
                    print("error sending message")
            return True
        return False
message_users.py 文件源码 项目:30-Days-of-Python 作者: codingforentrepreneurs 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def send_email(self):
        self.make_messages()
        if len(self.email_messages) > 0:
            for detail in self.email_messages:
                user_email = detail['email']
                user_message = detail['message']
                try:
                    email_conn = smtplib.SMTP(host, port)
                    email_conn.ehlo()
                    email_conn.starttls()
                    email_conn.login(username, password)
                    the_msg = MIMEMultipart("alternative")
                    the_msg['Subject'] = "Billing Update!"
                    the_msg["From"] = from_email
                    the_msg["To"]  = user_email
                    part_1 = MIMEText(user_message, 'plain')
                    the_msg.attach(part_1)
                    email_conn.sendmail(from_email, [user_email], the_msg.as_string())
                    email_conn.quit()
                except smtplib.SMTPException:
                    print("error sending message")
            return True
        return False
message_users.py 文件源码 项目:30-Days-of-Python 作者: codingforentrepreneurs 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def send_email(self):
        self.make_messages()
        if len(self.email_messages) > 0:
            for detail in self.email_messages:
                user_email = detail['email']
                user_message = detail['message']
                try:
                    email_conn = smtplib.SMTP(host, port)
                    email_conn.ehlo()
                    email_conn.starttls()
                    email_conn.login(username, password)
                    the_msg = MIMEMultipart("alternative")
                    the_msg['Subject'] = "Billing Update!"
                    the_msg["From"] = from_email
                    the_msg["To"]  = user_email
                    part_1 = MIMEText(user_message, 'plain')
                    the_msg.attach(part_1)
                    email_conn.sendmail(from_email, [user_email], the_msg.as_string())
                    email_conn.quit()
                except smtplib.SMTPException:
                    print("error sending message")
            return True
        return False
message_users.py 文件源码 项目:30-Days-of-Python 作者: codingforentrepreneurs 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def send_email(self):
        self.make_messages()
        if len(self.email_messages) > 0:
            for detail in self.email_messages:
                user_email = detail['email']
                user_message = detail['message']
                try:
                    email_conn = smtplib.SMTP(host, port)
                    email_conn.ehlo()
                    email_conn.starttls()
                    email_conn.login(username, password)
                    the_msg = MIMEMultipart("alternative")
                    the_msg['Subject'] = "Billing Update!"
                    the_msg["From"] = from_email
                    the_msg["To"]  = user_email
                    part_1 = MIMEText(user_message, 'plain')
                    the_msg.attach(part_1)
                    email_conn.sendmail(from_email, [user_email], the_msg.as_string())
                    email_conn.quit()
                except smtplib.SMTPException:
                    print("error sending message")
            return True
        return False
message_users.py 文件源码 项目:30-Days-of-Python 作者: codingforentrepreneurs 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def send_email(self):
        self.make_messages()
        if len(self.email_messages) > 0:
            for detail in self.email_messages:
                user_email = detail['email']
                user_message = detail['message']
                try:
                    email_conn = smtplib.SMTP(host, port)
                    email_conn.ehlo()
                    email_conn.starttls()
                    email_conn.login(username, password)
                    the_msg = MIMEMultipart("alternative")
                    the_msg['Subject'] = "Billing Update!"
                    the_msg["From"] = from_email
                    the_msg["To"]  = user_email
                    part_1 = MIMEText(user_message, 'plain')
                    the_msg.attach(part_1)
                    email_conn.sendmail(from_email, [user_email], the_msg.as_string())
                    email_conn.quit()
                except smtplib.SMTPException:
                    print("error sending message")
            return True
        return False
message_users.py 文件源码 项目:30-Days-of-Python 作者: codingforentrepreneurs 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def send_email(self):
        self.make_messages()
        if len(self.email_messages) > 0:
            for detail in self.email_messages:
                user_email = detail['email']
                user_message = detail['message']
                try:
                    email_conn = smtplib.SMTP(host, port)
                    email_conn.ehlo()
                    email_conn.starttls()
                    email_conn.login(username, password)
                    the_msg = MIMEMultipart("alternative")
                    the_msg['Subject'] = "Billing Update!"
                    the_msg["From"] = from_email
                    the_msg["To"]  = user_email
                    part_1 = MIMEText(user_message, 'plain')
                    the_msg.attach(part_1)
                    email_conn.sendmail(from_email, [user_email], the_msg.as_string())
                    email_conn.quit()
                except smtplib.SMTPException:
                    print("error sending message")
            return True
        return False
message_users.py 文件源码 项目:30-Days-of-Python 作者: codingforentrepreneurs 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def send_email(self):
        self.make_messages()
        if len(self.email_messages) > 0:
            for detail in self.email_messages:
                user_email = detail['email']
                user_message = detail['message']
                try:
                    email_conn = smtplib.SMTP(host, port)
                    email_conn.ehlo()
                    email_conn.starttls()
                    email_conn.login(username, password)
                    the_msg = MIMEMultipart("alternative")
                    the_msg['Subject'] = "Billing Update!"
                    the_msg["From"] = from_email
                    the_msg["To"]  = user_email
                    part_1 = MIMEText(user_message, 'plain')
                    the_msg.attach(part_1)
                    email_conn.sendmail(from_email, [user_email], the_msg.as_string())
                    email_conn.quit()
                except smtplib.SMTPException:
                    print("error sending message")
            return True
        return False
send_mail.py 文件源码 项目:base_function 作者: Rockyzsu 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def send_139():
    cfg = Toolkit.getUserData('data.cfg')
    sender = cfg['mail_user']
    passwd = cfg['mail_pass']
    receiver = cfg['receiver']
    msg = MIMEText('Python mail test', 'plain', 'utf-8')
    msg['From'] = Header('FromTest', 'utf-8')
    msg['To'] = Header('ToTest', 'utf-8')
    subject = 'Python SMTP Test'
    msg['Subject'] = Header(subject, 'utf-8')
    try:
        obj = smtplib.SMTP()
        obj.connect('smtp.126.com', 25)
        obj.login(sender, passwd)
        obj.sendmail(sender, receiver, msg.as_string())
    except smtplib.SMTPException, e:
        print e
smtp.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def close(self):
        """Closes the connection to the email server."""
        if self.connection is None:
            return
        try:
            try:
                self.connection.quit()
            except (ssl.SSLError, smtplib.SMTPServerDisconnected):
                # This happens when calling quit() on a TLS connection
                # sometimes, or when the connection was already disconnected
                # by the server.
                self.connection.close()
            except smtplib.SMTPException:
                if self.fail_silently:
                    return
                raise
        finally:
            self.connection = None
mass_mailer.py 文件源码 项目:massmailer 作者: m57 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def send_mail(server, from_address, from_name, to_address, subject, body_arg, return_addr, tls):

    msg = MIMEMultipart('alternative')
    msg['To'] = to_address
    msg['Date'] = formatdate(localtime = True)
    msg['Subject'] = subject
    msg.add_header('reply-to', return_addr)
    msg.add_header('from', from_name + "<" + from_address + ">")

    part1 = MIMEText(body_arg, 'plain')
    part2 = MIMEText(body_arg, 'html')

    msg.attach(part1)
    msg.attach(part2)

    try:
        smtp = smtplib.SMTP(server)
        smtp.set_debuglevel(VERBOSE)
        smtp.sendmail(from_address, to_address, msg.as_string())
        smtp.quit()
    except smtplib.SMTPException:
        print FAIL + "[-] Error: unable to send email to ", to_address, ENDC

# --------------------- PARSE includes/config.massmail -------------------
smtpd.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _deliver(self, mailfrom, rcpttos, data):
        import smtplib
        refused = {}
        try:
            s = smtplib.SMTP()
            s.connect(self._remoteaddr[0], self._remoteaddr[1])
            try:
                refused = s.sendmail(mailfrom, rcpttos, data)
            finally:
                s.quit()
        except smtplib.SMTPRecipientsRefused as e:
            print('got SMTPRecipientsRefused', file=DEBUGSTREAM)
            refused = e.recipients
        except (socket.error, smtplib.SMTPException) as e:
            print('got', e.__class__, file=DEBUGSTREAM)
            # All recipients were refused.  If the exception had an associated
            # error code, use it.  Otherwise,fake it with a non-triggering
            # exception code.
            errcode = getattr(e, 'smtp_code', -1)
            errmsg = getattr(e, 'smtp_error', 'ignore')
            for r in rcpttos:
                refused[r] = (errcode, errmsg)
        return refused
FortiMail.py 文件源码 项目:Fortigate-Anomally-Alert 作者: farcompen 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def mail(self):

        gonderen = "sender e-mail"
        pswd = "sender e-mail passwd"
        alici = "receiver e mail "
        cc = "if you need add cc e-mail "
        body=self.mesaj
        messg = MIMEMultipart()
        messg['To'] = alici
        messg['Cc'] = cc
        messg['From'] = gonderen
        messg['Subject'] = "ANomaly tespit sistemi"

        text = MIMEText(body, 'plain')
        messg.attach(text)
        print(self.mesaj)
        try:
            server = smtplib.SMTP("smtp.live.com", 587)
            server.starttls()
            server.login(gonderen, pswd)
            server.sendmail(gonderen,[alici,cc,alici],messg.as_string())
            server.close()
            print("mail gönderildi")
        except smtplib.SMTPException as e:
            print(str(e))
smtp.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def close(self):
        """Closes the connection to the email server."""
        if self.connection is None:
            return
        try:
            try:
                self.connection.quit()
            except (ssl.SSLError, smtplib.SMTPServerDisconnected):
                # This happens when calling quit() on a TLS connection
                # sometimes, or when the connection was already disconnected
                # by the server.
                self.connection.close()
            except smtplib.SMTPException:
                if self.fail_silently:
                    return
                raise
        finally:
            self.connection = None
smtp.py 文件源码 项目:DjangoBlog 作者: 0daybug 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def close(self):
        """Closes the connection to the email server."""
        if self.connection is None:
            return
        try:
            try:
                self.connection.quit()
            except (ssl.SSLError, smtplib.SMTPServerDisconnected):
                # This happens when calling quit() on a TLS connection
                # sometimes, or when the connection was already disconnected
                # by the server.
                self.connection.close()
            except smtplib.SMTPException:
                if self.fail_silently:
                    return
                raise
        finally:
            self.connection = None
demo_smtp.py 文件源码 项目:BAPythonDemo 作者: boai 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def ba_smtp_sendEmail(email_title, email_content, email_type, email_sender, email_receiver, email_host, email_user, email_pwd):

    # ??, ??, ??
    message = MIMEText(email_content, email_type, 'utf-8')
    message['From'] = '{}'.format(email_sender)
    message['To'] = ','.join(email_receiver)
    message['Subject'] = email_title

    try:
        # ??SSL??, ?????465
        smtpObj = smtplib.SMTP_SSL(email_host, 465)
        # ????
        smtpObj.login(email_user, email_pwd)
        # ??
        smtpObj.sendmail(email_sender, email_receiver, message.as_string())
        print('??????!')
    except smtplib.SMTPException as e:
        print("Error: ??????")
        print(e)


问题


面经


文章

微信
公众号

扫码关注公众号