# -*- coding: utf-8 -*- # 安装 yagmail # pip install yagmail # yagmail.SMTP(user, password, host) user:发件人的邮箱地址, password:邮箱的SMTP服务授权码, host:邮箱的SMTP服务地址 # send(to, subject, contents) 收件人的邮箱地址、邮件主题、邮件内容 import yagmail mail = yagmail.SMTP('[email protected]', 'xxxx', 'smtp.163.com') def demo1(): for i in range(1): mail.send('[email protected]', f'测试邮件{i+1}', '你好啊!') mail.close() # 批量发送 def demo2(): for i in range(1): to_list = ['[email protected]', '[email protected]'] content = ['早上好,', '昨日网站新增用户168万人', '请查收。'] mail.send(to_list, f'测试邮件{i+1}', contents=content, bcc='[email protected]') # 自定义邮件内容 def demo3(): for i in range(1): to_list = ['[email protected]', '[email protected]'] content = ['早上好,', '昨日网站新增用户168万人', '请查收。', yagmail.inline(r'D:\学习文件\测试\python\快学Python源文件\第9章 学习Python,可以自动化操作通信软件\测试图片.png'), '<a href="http://www.baidu.com">图片详情链接地址</a>'] mail.send(to_list, f'自定义邮件{i+1}', contents=content, bcc='[email protected]') # demo1() # demo2() demo3()
标签:content,python,send,发送,mail,yagmail,com,邮件 From: https://www.cnblogs.com/zhaoyiguang/p/16714064.html