def _build_multipart_msg(message, images):
 _LOGGER.debug('Building multipart email with embedded attachment(s)')
 msg = MIMEMultipart('related')
 msg_alt = MIMEMultipart('alternative')
 msg.attach(msg_alt)
 body_txt = MIMEText(message)
 msg_alt.attach(body_txt)
 body_text = ['<p>{}</p><br>'.format(message)]
 for (atch_num, atch_name) in enumerate(images):
  cid = 'image{}'.format(atch_num)
  body_text.append('<img src="cid:{}"><br>'.format(cid))
  try:
   with open(atch_name, 'rb') as attachment_file:
    attachment = MIMEImage(attachment_file.read())
    msg.attach(attachment)
    attachment.add_header('Content-ID', '<{}>'.format(cid))
  except FileNotFoundError:
   _LOGGER.warning('Attachment %s not found. Skipping', atch_name)
 body_html = MIMEText(''.join(body_text), 'html')
 msg_alt.attach(body_html)
 return msg

def _build_multipart_msg ( message , images ) : _LOGGER . debug ( 'Building multipart email with embedded attachment(s)' ) msg = MIMEMultipart ( 'related' ) msg_alt = MIMEMultipart ( 'alternative' ) msg . attach ( msg_alt ) body_txt = MIMEText ( message ) msg_alt . attach ( body_txt ) body_text = [ '<p>{}</p><br>' . format ( message ) ] for ( atch_num , atch_name ) in enumerate ( images ) : cid = 'image{}' . format ( atch_num ) body_text . append ( '<img src="cid:{}"><br>' . format ( cid ) ) try : with open ( atch_name , 'rb' ) as attachment_file : attachment = MIMEImage ( attachment_file . read ( ) ) msg . attach ( attachment ) attachment . add_header ( 'Content-ID' , '<{}>' . format ( cid ) ) except FileNotFoundError : _LOGGER . warning ( 'Attachment %s not found. Skipping' , atch_name ) body_html = MIMEText ( '' . join ( body_text ) , 'html' ) msg_alt . attach ( body_html ) return msg
build multipart message with in-line images .