title: send html email with embedded image using python script
body: <p>I am newbie to Python. I wanted to send html based email with company logo embedded on top left to the email body. </p>
  
  <p>With the following code the email is absolutely working but not attaching the embedded image anymore. Not sure where i did mistake. Can anyone please help me out here.</p>
  
  <pre><code>import smtplib
  from email.mime.multipart import MIMEMultipart
  from email.mime.text import MIMEText
  from email.MIMEImage import MIMEImage
  
  msg = MIMEMultipart('alternative')
  msg['Subject'] = "My text dated %s" % (today)
              msg['From'] = sender
              msg['To'] = receiver
  
  html = """\
  &lt;html&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;body&gt;
    &lt;img src="cid:image1" alt="Logo" style="width:250px;height:50px;"&gt;&lt;br&gt;
    &lt;p&gt;&lt;h4 style="font-size:15px;"&gt;Some Text.&lt;/h4&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  """
  
  # The image file is in the same directory as the script
  fp = open('logo.png', 'rb')
  msgImage = MIMEImage(fp.read())
  fp.close()
  
  msgImage.add_header('Content-ID', '&lt;image1&gt;')
  msg.attach(msgImage)
  
  part2 = MIMEText(html, 'html')
  msg.attach(part2)
  
  mailsrv = smtplib.SMTP('localhost')
  mailsrv.sendmail(sender, receiver, msg.as_string())
  mailsrv.quit()
  </code></pre>