python - Python 使用带有 html 内容的 csv 发送多封电子邮件?
问题描述
import csv, smtplib
port = 2525
smtp_server = "smtp.mailtrap.io"
login = "1a2b3c4d5e6f7g" # paste your login generated by Mailtrap
password = "1a2b3c4d5e6f7g" # paste your password generated by Mailtrap
message = """Subject: Order confirmation
To: {recipient}
From: {sender}
Hi {name}, thanks for your order! We are processing it now and will contact you soon"""
sender = "new@example.com"
with smtplib.SMTP("smtp.mailtrap.io", 2525) as server:
server.login(login, password)
with open("contacts.csv") as file:
reader = csv.reader(file)
next(reader) # it skips the header row
for name, email in reader:
server.sendmail(
sender,
email,
message.format(name=name, recipient=email, sender=sender)
)
print(f'Sent to {name}')
在消息 Hi{name} 之后,我需要添加 html 代码,这是我的内容。但是当我粘贴时,我的内容中也有 html 标签
解决方案
推荐阅读
- mysql - 从 Oracle 查询 MySQL 需要在字段名周围加上引号
- bootstrap-4 - Toasts 是不可见的,不能在 Bootstrap 4 中关闭
- testing - 使用 Cypress 测试依赖 OAuth 的应用程序
- excel - 如何匹配多个条件并获取消息
- javascript - JS 学士考试算法
- c++ - 有没有机会在不知道拥有队列的情况下触发 kevent?有什么选择吗?
- php - 主键缺失值
- java - 如果我在成功下载后启动动态模块中的活动,则会出现 classnotfoundException
- python - 如何在python的文件夹中使用PIL调整图像大小
- c# - c# 字典不抛出 KeyNotFound 异常?