#!/usr/bin/python
# coding: utf-8
import smtplib
from email.mime.text import MIMEText
from email.header import Header
sender = 'xxxxxxxx@163.com'
receiver = '874247458@qq.com'
subject = 'python 调试'
smtpserver = 'smtp.163.com'
username = 'xxxxxxxx@163.com' #发送邮件的邮箱
password = '*************' #发送邮件的邮箱密码
msg = MIMEText('你好') # 中文需参数‘utf-8',单字节字符不需要
msg['Subject'] = Header(subject, 'utf-8')
msg["from"] = sender
msg["to"] = receiver
smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
print '邮件发送成功!'转载于:https://blog.51cto.com/gosweet/1898777
本文介绍了一个简单的Python脚本,该脚本使用smtplib库通过163邮箱服务发送电子邮件。示例展示了如何配置发件人、收件人、主题及正文,并连接到SMTP服务器进行邮件发送。
287

被折叠的 条评论
为什么被折叠?



