https://m.qihuiwang02.com
https://m.nuodagold.com
https://m.xuxinfangshui.com
https://m.fjstyjy.com
yagmail是一个专为Python设计的邮件发送库,它简化了通过SMTP发送邮件的复杂过程。与Python内置的smtplib相比,yagmail提供了更简洁、更Pythonic的API。
主要优点:
使用pip安装:
pip install yagmailimport yagmail
# 初始化客户端(首次使用会提示输入密码)
yag = yagmail.SMTP('your_email@gmail.com', host='smtp.gmail.com')
# 发送邮件
yag.send(
to='recipient@example.com',
subject='测试邮件',
contents='这是一封来自yagmail的测试邮件!'
)html_content = """
<h1 style="color: #3498db;">欢迎加入我们!</h1>
<p>感谢您注册我们的服务。</p>
<ul>
<li>账户已激活</li>
<li>您现在可以登录</li>
</ul>
"""
yag.send(
to='recipient@example.com',
subject='欢迎邮件',
contents=html_content
)# 单个附件
yag.send(
to='recipient@example.com',
subject='月度报告',
contents='请查收附件中的月度报告',
attachments=['/path/to/report.pdf']
)
# 多个附件
yag.send(
to='recipient@example.com',
subject='项目文档',
contents='项目相关文档见附件',
attachments=['doc1.docx', 'data.xlsx', 'image.png']
)recipients = ['user1@example.com', 'user2@example.com', 'user3@example.com']
yag.send(
to=recipients,
subject='重要通知',
contents='请所有成员注意下周会议时间变更'
)yagmail可以在keyring中安全存储密码:
# 首次运行时,会提示输入密码
yagmail.register('your_email@gmail.com', 'your_password')yag.send(
to='recipient@example.com',
subject='来自开发团队',
contents='这是邮件内容',
headers={'From': 'Dev Team <dev@company.com>'}
)contents = [
"<h1>产品图片</h1>",
"<p>这是我们最新产品的图片:</p>",
yagmail.inline('/path/to/product.jpg'),
"<p>欢迎反馈!</p>"
]
yag.send(to='recipient@example.com', subject='产品图片', contents=contents)确保在Google账户中启用了"安全性较低的应用的访问权限"或使用应用专用密码。
yagmail支持所有SMTP服务,包括:
# 使用bcc参数
yag.send(
bcc=['user1@example.com', 'user2@example.com'],
subject='机密通知',
contents='这封邮件是密送的'
)原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。