def zmail_email():
import zmail, traceback
from_mailbox = 'xxxx@qq.com'
password = 'xxxxxxxx'
smtp_server = 'smtp.exmail.qq.com'
to_mailbox = ['xxxx@qq.com',
'xxxx@163.com']
cc_mailbox = ['xxxx@qq.com',
'xxxx@qq.com',
'xxxx@139.com']
subject = '发送邮件测试'
content_html = """
<html>
<head></head>
<body>
<p>您好:<br> 以下为测试邮件<br>
How are you?<br>
Here is the <a href="http://www.baidu.com">link</a> you wanted.<br>
</p>
<img src="cid:image1">
</body>
</html>
"""
attachment = ['测试附件.xlsx', 'test.png']
zm = zmail.server(from_mailbox, password, smtp_host='smtp.exmail.qq.com', smtp_port=465, smtp_ssl=True)
mail = {
'subject': subject,
'from': '发送者<xxxx@qq.com>',
'content_html': content_html,
'attachments': attachment
}
try:
zm.send_mail(to_mailbox, mail, cc=cc_mailbox)
print('邮件发送成功!')
except Exception as e:
print(traceback.print_exc())
print('邮件发送失败!')
def yagmail_email():
import yagmail
yag = yagmail.SMTP(user='xxxx@sina.com', password='xxxxxxxx', host='smtp.sina.com')
to = ['xxxx@qq.com','xxxx@139.com']
cc = ['xxxx@163.com','xxxx@qq.com']
subject = ["【温馨提醒】进度"]
picture = r'test.png'
logo = r'logo.png'
text = '''
Dear all,
为提高资金安全管理力度,基本每周邮件提醒催收应收款,本截图或附件是双子上截止到2022.6.19的数据。
如果在实际工作中,任何收款方式的应收款项,与协议上的回款时间严重不符合的,请告知相关负责人,谢谢'
'''
inscribe = """------------------
風£飛 运维开发部
XXXXX科技有限公司
北京市XXXX区XXXX路X号X层x-xxxx室
电话:xxxxxxxxxx
邮箱:xxxx@qq.com | 网址:https://www.cnblogs.com/xwupiaomiao
"""
contents = [text, yagmail.inline(picture), inscribe, yagmail.inline(logo)]
attachments = '测试附件.xlsx'
yag.send(to=to, cc=cc, subject=subject, contents=contents, attachments=attachments)
print("已发送")
if __name__ == '__main__':
zmail_email()
yagmail_email()