import yamail user = 'XX@qq.cn'#我自己的邮箱 passwold = 'xbaT82SpnwyaHFdn' #生成授权码(登录邮箱,设置pop3/smtp 开启,点击生成授权码) host ='smtp.qq.cn' mail = yamail.SMTP(host=host,user=user,password=passwold) mail.send( to=['xxx@qq.cn'], cc=[], subject='测试一下', contents='发送消息' )##to-接收人邮箱,cc-抄送人邮箱,subect-邮件主题,contents-邮件内容,attachments-邮件附件,可通过列表传多个附件 ,接收人,抄送人 mail.close()
import smtplib from email.mime.text import MIMEText from email.header import Header import poplib import base64,re from email.parser import Parser def mail(content): mail_host = "smtp.exmail.qq.com" # 设置服务器 mail_user = "song@xxx.cn" # 用户名 mail_pass = "xbaT82SpnwyaHFdn" # 口令 sender = 'song@xxx.cn' receivers = ['lei@sceneconsole.cn'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱 message = MIMEText(content, 'plain', 'utf-8') message['From'] = Header("song@xxx.cn", 'utf-8') message['To'] = Header("lei@xxx.com", 'utf-8') subject = "11.05-日报" message['Subject'] = Header(subject, 'utf-8') try: smtpObj = smtplib.SMTP() smtpObj.connect(mail_host, 25) # 25 为 SMTP 端口号 smtpObj.login(mail_user, mail_pass) smtpObj.sendmail(sender, receivers, message.as_string()) print("邮件发送成功") except smtplib.SMTPException: print("Error: 无法发送邮件") mail('早上好,今日计划如下: 1、测试大V后台 ')