前提是163邮箱要开通 POP3/SMTP/IMAP服务,截止2017年9月默认是不开通的
还要设置授权码(替代原先的登录密码password)
#coding=utf-8
import smtplib
from email.mime.text import MIMEText
from email.header import Header
import random
def fasong():
feihua=['**********”',
'******',
'****************'
]
n=random.randint(0,2)
'''发送邮箱'''
sender = '****@163.com' #企业263邮箱
'''接收邮箱'''
receiver = '*****@qq.com'
'''发送邮件主题'''
subject = feihua[n]
'''发送邮箱服务器'''
smtpserver = 'smtp.163.com'
'''发送邮箱用户/密码'''
username = '****@163.com'
password = '*********'
'''中文需参数‘utf-8’ ,单字节字符不需要'''
msg = MIMEText('这是*某人测试使用,请不要回复.如若给您造成困扰,请原谅我','plain','utf-8')
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = '***<***@163.com>'
msg['To'] = "*******@qq.com"
smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
print ("Email has been sent out!")
'''发送邮件20封'''
for num in range(0,20): fasong()