发布时间:2019-09-22 08:13:30编辑:auto阅读(2195)
前言:2014-05-22记录在hi baidu上,现在移过来
使用python向gmail发邮件
"""
发送邮件
1: 需要提供发送者的邮件、密码;接收者地址;
2:步骤:
a:Login 失败说明无法登陆;
b:登录成功则可以发送邮件;
c:退出
"""
class SendMailToServer():
"""docstring for SendMailToServer"""
def __init__(self, fromAddress, password, toAddress):
# my test mail
self.mail_username = fromAddress
self.mail_password = password
self.from_addr = self.mail_username
self.to_addrs = toAddress
# HOST & PORT
self.HOST = 'smtp.gmail.com'
self.PORT = 25
# Create SMTP Object
self.smtp = smtplib.SMTP()
def Login(self):
# 打印调试信息
self.smtp.set_debuglevel(1)
try:
self.smtp.connect( self.HOST, self.PORT )
except Exception, e:
print e, 'connect failed ...'
return False
# gmail uses ssl
self.smtp.starttls()
# login with username & password
try:
print 'loginning ...'
self.smtp.login( self.mail_username, self.mail_password )
except Exception, e:
print e, 'login faild ...'
return False
return True
上一篇: 查看Windows下TensorFlow
下一篇: [菜鸟实录]Python进行RSA加密
47831
46369
37253
34714
29299
25960
24876
19935
19518
18005
5776°
6401°
5912°
5954°
7054°
5898°
5929°
6425°
6390°
7759°