How to send eml file by email using python script to email list one at a time?

I want to write a simple python script that sends an EML file exported from Outlook, although this SMTP server is like email for this list of emails. I know how to send a simple email, but sending an eml file by email is not something that I could do and could not find it on Google. Can anyone help me on this. The EML file is actually in HTML format with embedded images. Any alternative suggestion is also welcome.

+3
source share
1 answer

Based on a emailsample module , try using a MIME application with HTML content. If the EML format is just HTML, this should work.

This example shows how to create a message with (html) attachments:

# 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)
#...
+3
source

Source: https://habr.com/ru/post/1746318/


All Articles