本文整理汇总了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)
示例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()