如何使用Python脚本将EML文件作为电子邮件发送给一个邮箱列表中的每个收件人?

3
我希望编写一个简单的Python脚本,将从Outlook导出的EML文件通过给定的SMTP服务器作为电子邮件发送到指定的电子邮件列表。我知道如何发送简单的电子邮件,但是发送EML文件作为电子邮件不是我能做到的,也没有在Google上找到相关信息。有人能帮我吗?该EML文件实际上是以HTML格式嵌入图像的。欢迎提供任何替代建议。
1个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
3

email模块示例的基础上,尝试使用MIME附件和HTML内容。如果EML格式只是HTML,则应该可以正常工作。

该示例演示了如何构建带有(html)附件的消息:

# Create the body of the message (a plain-text and an HTML version).
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"
html = """\
<html>
  <head></head>
  <body>
    <p>Hi!<br>
       How are you?<br>
       Here is the <a href="http://www.python.org">link</a> you wanted.
    </p>
  </body>
</html>
"""

# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')

# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)
#...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,