Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101272

create Email with multiple HTML blocks embedded

Newsgroups comp.lang.python
Date 2016-01-05 07:27 -0800
Message-ID <0f51af4b-dfef-4d27-92b7-be601677bf50@googlegroups.com> (permalink)
Subject create Email with multiple HTML blocks embedded
From kevind0718@gmail.com

Show all headers | View raw


The below script will send an email with one HTML file embedded and the second attached.  Not really what I need.  I need a Python script to create an email that contains multiple blocks of HTML in the body of the email.

There is a process that will create at least one HTML file but very often two. A summary and an exception web pages. These need to be emailed to a user group.

The code below displays one file in the email, but the other shows up as an attachment. If I reverse the body.attach statements then the files switch. I need both to appear in the body of the email.

I messed around with the boundary attribute, but could not get that to work.

Your kind assistance is requested.

Best Regards

KD


import smtplib
from pprint import pprint
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

msg = MIMEMultipart()
msg['Subject'] = 'email from Python with HTML content '
msg['From'] = 'kduf@xxx.com'
msg['To'] = 'kduf@xxx.com'

text = "\nBelow I hope will be the Summary Table in HTML\n\n"
body = MIMEMultipart('multipart')

with open("H:\\dev\\testHTML\\Exceptions_SheetDec30d.htm", "r") as fE:
    htmlE = fE.read().replace('\n', '')


with open("H:\\dev\\testHTML\\Summary_SheetDec30d.htm", "r") as f:
    html = f.read().replace('\n', '')

body.attach(MIMEText(html, 'html'))
body.attach(MIMEText(htmlE, 'html'))

msg.attach(body)

s = smtplib.SMTP('smtp.aigfpc.com')  # ('localhost')
s.sendmail('kduf@xxx.com', ['kduf@xxx.com'], msg.as_string())
s.quit()

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

create Email with multiple HTML blocks embedded kevind0718@gmail.com - 2016-01-05 07:27 -0800
  Re: create Email with multiple HTML blocks embedded Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-06 00:58 +0100
  Re: create Email with multiple HTML blocks embedded Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-31 22:34 +0100
    Re: create Email with multiple HTML blocks embedded Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-31 22:37 +0100

csiph-web