当前位置: 首页>>代码示例>>Python>>正文


Python SMTP.verify方法代码示例

本文整理汇总了Python中smtplib.SMTP.verify方法的典型用法代码示例。如果您正苦于以下问题:Python SMTP.verify方法的具体用法?Python SMTP.verify怎么用?Python SMTP.verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在smtplib.SMTP的用法示例。


在下文中一共展示了SMTP.verify方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SMTPTest

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import verify [as 别名]
class SMTPTest(unittest.TestCase):
    def setUp(self):
        self.server = SMTP('smtp-pdx.wk.com')
        self.validEmail = '[email protected]'
        self.invalidEmail = '[email protected]'

    def test_email_is_valid(self):
        verify_code = self.server.verify(self.validEmail)
        self.assertTrue(verify_code[0] < 400)

    def test_email_not_verified(self):
        verify_code = self.server.verify(self.validEmail)
        self.assertTrue(verify_code[0] == 252)

    def test_email_not_valid(self):
        verify_code = self.server.verify(self.invalidEmail)
        self.assertTrue(verify_code[0] >= 400)
开发者ID:keithhamilton,项目名称:csv2email,代码行数:19,代码来源:test.py

示例2: EmailConnection

# 需要导入模块: from smtplib import SMTP [as 别名]
# 或者: from smtplib.SMTP import verify [as 别名]
class EmailConnection(object):
    def __init__(self, server, username, password, debug=False):
        if ':' in server:
            data = server.split(':')
            self.server = data[0]
            self.port = int(data[1])
        else:
            self.server = server
            self.port = 25
        self.username = username
        self.password = password
        self.connect(debug)

    def __enter__(self):
        return self

    def __exit__(self, exception_type, exception_val, trace):
        self.close()

    def connect(self, debug):
        self.connection = SMTP(host=self.server, port=self.port)
        if debug:  # Debug Information
            # self.debuglevel = 1
            self.connection.set_debuglevel(debug)
        # identify ourselves, prompting server for supported features
        self.connection.ehlo()
        # If we can encrypt this session, do it
        if self.connection.has_extn('STARTTLS'):
            self.connection.starttls()
            self.connection.ehlo()
        self.connection.esmtp_features['auth'] = 'PLAIN LOGIN'
        self.connection.login(self.username, self.password)

    def send(self, message, from_=None, to=None, verify=False):
        if type(message) == str:
            if from_ is None or to is None:
                raise EmailConnectionError('You need to specify `from_` '
                                           'and `to`')
            else:
                from_ = get_email(from_)
                to = get_email(to)
        else:
            from_ = message.email['From']
            if 'Cc' not in message.email:
                message.email['Cc'] = ''
            if 'bcc' not in message.email:
                message.email['bcc'] = ''
            to_emails = list(message.email['To'].split(',')) + \
                        message.email['Cc'].split(',') + \
                        message.email['bcc'].split(',')
            to = [get_email(complete_email) for complete_email in to_emails]
            message = str(message)
            if verify:
                for each_email in to_emails:
                    self.connection.verify(each_email)
                    # TODO option - remove emails that failed verification
        # return self.connection.sendmail(from_, to, message)
        try:
            self.connection.sendmail(from_, to, message)
        except SMTPException:
            raise SendEmailError('Message Could not be sent!')

    def close(self):
        self.connection.close()
开发者ID:atvKumar,项目名称:TheWatcher,代码行数:66,代码来源:mkEmail.py


注:本文中的smtplib.SMTP.verify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。