Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a EML file as email using python script to list of emails one at a time?

I want to write a simple python script that send a EML file exported from Outlook though given smtp server as email to a given list of emails. I know how to send a simple email but sending a EML file as email is not something i could do and could not find it on Google. Can anyone help me with that. The EML file is actually in HTML format with embedded images. Any alternate suggestion is also welcome.

like image 811
particle Avatar asked Oct 27 '25 08:10

particle


1 Answers

Building on the email module example, try using a MIME attachment with HTML content. If the EML format is just HTML, this should work.

The example shows how to construct 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)
#...
like image 156
gimel Avatar answered Oct 30 '25 00:10

gimel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!