yagmail如何隐藏收件人

时间:2018-09-04 19:40:13

标签: python python-3.x yagmail

我正在尝试通过yagmail开发大量电子邮件脚本。我的脚本可以正常工作,但是我想要的是在“收件人”字段中仅显示接收收件人的电子邮件,而不是所有其他收件人。例如。如果我将电子邮件发送到example1@email.com和example2@email.com,则example1应该在“收件人”字段中看到example1 @ email.com,example2应该看到example2@email.com。

有没有办法做到这一点?还是我必须通过send_mail对每个收件人使用循环?

这是我的剧本

import yagmail

with open("folder/email.txt") as f:
    recipients = f.read()

yag = yagmail.SMTP('my.username')

email_subject = 'A subject'
embedded_image = yagmail.inline("folder/image.png")
message1 = '<p>lorem impsum lorem ipsum</p>'
message2 = '<p>lorem impsum lorem ipsum</p>'
attachment1 = 'folder/image.png'
attachment2 = 'folder/file.pdf'


yag.send(to = recipients, subject = email_subject, contents = [message1, embedded_image, message2, attachment1, attachment2])

1 个答案:

答案 0 :(得分:1)

实际上,单个消息无法为不同的收件人提供不同的标题。您必须遍历收件人并向每个收件人发送单独的消息。

可能的替代方法可能是使用bcc并可能将自己设为明确的to接收者。

相关问题