1、注册163邮箱并登陆
https://mail.163.com
2、开启 IMAP/IMAP
服务
3、编写代码,进行发邮件操作
import smtplib
from email.mime.text import MIMEText
from email.header import Header
# 发送邮箱服务器
smtp_server = 'smtp.163.com'
# 发送邮箱用户名密码(授权码)
username = 'your_email@163.com'
password = 'your_email_password'
# 发送邮箱
sender = 'your_email@163.com'
# 接收邮箱
receiver = 'receiver_email@xxx.com'
# 发送邮件主题和内容
subject = 'Python SMTP 邮件测试'
content = '这是一封来自 Python SMTP 的测试邮件'
# HTML邮件正文
message = MIMEText(content, 'html', 'utf-8')
message['Subject'] = Header(subject, 'utf-8')
message['From'] = Header(sender, 'utf-8')
message['To'] = Header(receiver)
# 发送邮件
try:
smtpObj = smtplib.SMTP()
smtpObj.connect(smtp_server, 25)
smtpObj.login(username, password)
smtpObj.sendmail(sender, receiver, message.as_string())
print("邮件发送成功")
except smtplib.SMTPException as e:
print("Error: 无法发送邮件", e)