title: Sending email with embedded image using SMTP
body: <p>I'm trying to send an email using the SMTP library with an embedded image in the body. The email gets sent, but the resulting image is a textbox saying 'This image cannot be displayed, it was possibly removed or renamed...' etc. I know there is nothing wrong with the image itself as I can open the image locally just fine. The path and image both are valid, so I don't understand why it cannot be displayed within the email.
  I read somewhere that I may be because of the <code>Content-ID</code> being too short, but I have no idea how to find a solution for that.</p>
  <p>This is the code I have for sending the email in the method <code>send_email()</code></p>
  <pre><code>def send_email():
      msg = MIMEMultipart('alternative')
      msg['Subject'] = &quot;Subject&quot;
      msg['From'] = from_address
      msg['To'] = to_address
  
      text = MIMEText('&lt;img src=&quot;cid:image1&quot;&gt;', 'html')
      msg.attach(text)
  
      image = MIMEImage(open('pictures/download.png', 'rb').read())
  
      image.add_header('Content-ID', '&lt;ímage1&gt;')
      msg.attach(image)
  
      try:
          s = smtplib.SMTP(host='smtp-mail.outlook.com', port=587)
          s.starttls()
          s.login(from_address, password)
          s.sendmail(from_address, to_address, msg.as_string())
          s.quit()
          print('Email sent!')
  
      except Exception as ex:
          print('Error:', ex)
  
  </code></pre>
  <p>So I'm guessing that there is a problem with the <code>Content-ID</code>, but I'm not sure. Has anyone else encountered this?</p>