50  邮箱

50.1 发送附件

import yagmail, os
from myconfig import mail_user, mail_password
yag = yagmail.SMTP(user=mail_user, password= mail_password, host='smtp.163.com')
attached_file = 'untitled.txt'
yag.send(to=['hulinhui@live.cn'], 
         subject='提醒:临床试验新注册', 
         contents=['茂名市人民医院有新注册,请督促项目负责人及时备案', attached_file])
yag.close()

50.2 发送html内容至多个邮件

## 发送邮件
import yagmail
import pandas as pd
from myconfig import mail_user, mail_password
yag = yagmail.SMTP(user=mail_user, password= mail_password, host='smtp.163.com')

# 发送邮件
# 创建示例数据
data = {'Name': ['John', 'Mike', 'Sarah'],
        'Age': [25, 30, 28],
        'City': ['New York', 'London', 'Paris']}
df = pd.DataFrame(data)

# 将DataFrame转换为HTML格式字符串
html_content = df.to_html()


# 多个邮箱地址
recipient_list = ['hulinhui@live.cn', 'hulihuihong@163.com']

yag.send(to=recipient_list, 
         subject='提醒:茂名市人民医院有新的临床试验注册,需确认项目负责人有无及时备案', 
         contents = html_content)

# 关闭SMTP连接
yag.close()