直接上代码吧 然后采用者直接写好自己的信息就可以运行啦
import smtplib
from email.mime.text import MIMEText
from email.header import Header
mail_host = "smtp.qq.com" #邮箱服务器(这里采用的是QQ的)
mail_user = "******@qq.com" #发送者的邮箱地址
mail_pass = "*********" #发送者的邮箱授权码
sender = '******@qq.com' #与发送者的邮箱保持一致
receivers = ['*******@qq.com','*******@qq.com'] #收件人的邮箱地址(可以一次给多人发送)
message = MIMEText('文本内容', 'plain', 'utf-8') #邮件的类型 这里采用的是纯文本的形势
message['From'] = Header('发件人名称', 'utf-8')
message['To'] = Header("收件人提示", 'utf-8')
subject = '邮件标头'
message['Subject'] = Header(subject, 'utf-8')
try:
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 25)#开放的邮箱服务器的端口
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print('发送成功!')
except smtplib.SMTPException:
print('发送失败!')
|