使用python调用第三方邮箱群发邮件 第三方邮件需要设置授权码这里是163邮箱,图上传不了。 设置===>邮箱安全设置===>客户端授权密码 代码部分: #!/usr/bin/env python #__*__coding:utf-8__*__ import smtplib from email.mime.text import MIMEText as mimetext from email.mime.multipart import MIMEMultipart #发件服务器地址 mail_host = ‘smtp.163.com‘ #发件邮箱地址 sender_user = ‘xxxx_monitor@163.com‘ #mail_pass = ‘xxxxx‘#登录密码 #邮箱授权码,不是登录密码 sender_pass = ‘xxxx‘ #收件邮箱地址 receivers = [‘receiver1@163.com‘,‘receiver2@people.cn‘] #邮件内容 message = mimetext(‘Python 邮件测试发送‘,‘plain‘,‘utf-8‘) #发送邮箱地址 message[‘From‘] = sender_user #群发邮件时会报错message[‘To‘]不支持列表,使用join函数把地址合成字符串 message[‘To‘] = ",".join(receivers) #邮件主题 subject = ‘Python SMTP 邮件测试‘ message[‘Subject‘] = subject # try: # smtpobj = smtplib.SMTP() # smtpobj.connect(mail_host,25) # smtpobj.login(mail_user,mail_pass) # smtpobj.sendmail(sender,receivers,message) # print ‘邮件发送成功‘ # except: # print "邮件发送失败" smtpobj = smtplib.SMTP() smtpobj.connect(mail_host,25) smtpobj.login(sender_user,sender_pass) smtpobj.sendmail(sender_user,receivers,message.as_string()) smtpobj.close()
本文出自 “LINUX” 博客,请务必保留此出处http://wangpengtai.blog.51cto.com/3882831/1950887
原文地址:http://wangpengtai.blog.51cto.com/3882831/1950887