利用yagmail经过网易邮箱SMTP经传发送邮件。
- 1 前往网易邮箱开启发送方邮箱的SMTP
- 2 使用yagmail发送邮件
import yagmail
# 初始化 yagmail 客户端
yag = yagmail.SMTP(user='your_email@163.com', password='your_auth_password', host='smtp.163.com', port=465)
# 收件人邮箱
to = 'reverser_email@163.com'
# 邮件主题
subject = 'Test Email from NetEase'
# 邮件内容
contents = [
'Hello, this is a test email sent using yagmail via NetEase SMTP.',
'You can also send attachments.',
'attachment.txt' # 附件文件路径
]
# 发送邮件
yag.send(to, subject, contents)
print('Email sent successfully!')