import yagmail
username = '邮箱地址@qq.com'
passwd = '登陆密码'
mail = yagmail.SMTP(
user=username,
password=passwd,
host='smtp.qq.com',
smtp_ssl=True
) # smtp_ssl=True 如果用的是qq邮箱使用是安全协议的话
mail.send(
to='收件人邮箱地址@qq.com', # 如果多个收件人的话,写成list就行了
subject='网站数据备份',
contents='各位好!<br>'
'本次共计备份了5个文件,其执行的结果见附件。',
attachments=[
r'/root/博客数据库.sql',
r'/etc/nginx/conf.d/blog.conf']
)
print('发送成功')