首页 > 技术文章 > python3发送邮件(yagmail)

sammy1989 2017-12-19 17:01 原文

# coding:utf-8

import yagmail

# 链接邮箱服务器
yag = yagmail.SMTP(user="xxx@xx.com", password="xxx!!", host='smtp.xxx.com')

# 邮箱正文
contents = ['This is the body, and here is just text http://somedomain/image.png',
'You can find an audio file attached.', '/local/path/song.mp3','测试邮件']

# 发送邮件
yag.send(['xxx@xx.com', 'xxxxxx@xx.com'], '发送附件', contents, ['test.html', 'logo.jpg', 'yagmal_test.txt'])

#抄送
# 邮箱正文  文本及附件
contents = ['This is the body, and here is just text http://somedomain/image.png',
'You can find an audio file attached.', '/local/path/song.mp3', '测试邮件', 'test.html', 'logo.jpg',
'yagmal_test.txt']

# 发送邮件
yag.send(to='xx@xx.com', cc='xxx@xxx.com', subject='发送附件', contents=contents)
 

推荐阅读