title: Image not going as a body of email but some random lines are coming
body: <p>I have written a script that sends image as the body of the email. But instead of image, random lines are coming. This is my script:</p>
  
  <pre><code>from email.MIMEMultipart import MIMEMultipart
  from email.MIMEText import MIMEText
  from email.MIMEImage import MIMEImage
  
  
  msgRoot = MIMEMultipart('related')
  msgRoot['Subject'] = 'test message'
  msgRoot['From'] = strFrom
  msgRoot['To'] = strTo
  msgRoot.preamble = 'This is a multi-part message in MIME format.'
  
  msgAlternative = MIMEMultipart('alternative')
  msgRoot.attach(msgAlternative)
  
  msgText = MIMEText('This is the alternative plain text message.')
  msgAlternative.attach(msgText)
  
  
  msgText = MIMEText('&lt;b&gt;Some &lt;i&gt;HTML&lt;/i&gt; text&lt;/b&gt; and an image.&lt;br&gt;&lt;img src="cid:image1"&gt;&lt;br&gt;Nifty!', 'html')
  msgAlternative.attach(msgText)
  
  
  fp = open('test.jpg', 'rb')
  msgImage = MIMEImage(fp.read())
  fp.close()
  
  msgImage.add_header('Content-ID', '&lt;image1&gt;')
  msgRoot.attach(msgImage)
  
  
  import smtplib
  
  server = 'smtp.gmail.com'
  port = 587
  
  sender = 'mysender@gmail.com'
  recipient = 'myreceiver@gmail.com'
  subject = 'Gmail SMTP Test'
  body = 'blah blah blah'
  
  "Sends an e-mail to the specified recipient."
  
  body = "" + body + "" + msgImage.as_string()
  
  #This is where I have attached the image in body. 
  
  headers = ["From: " + sender,
             "Subject: " + subject,
             "To: " + recipient,
             "MIME-Version: 1.0",
             "Content-Type: text/html"]
  headers = "\r\n".join(headers)
  
  session = smtplib.SMTP(server, port)
  
  session.ehlo()
  session.starttls()
  session.ehlo
  session.login(sender, 'mypassword')
  
  session.sendmail(sender, recipient, headers + "\r\n\r\n" + body)
  session.quit()
  </code></pre>
  
  <p>This is what I receive on mail :</p>
  
  <p>blah blah blahContent-Type: image/jpeg MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-ID: /9j/4AAQSkZJRgABAQEAYABgAAD/4QBaRXhpZgAATU0AKgAAAAgABQMBAAUAAAABAAAASgMDAAEA AAABAAAAAFEQAAEAAAABAQAAAFERAAQAAAABAAAOw1ESAAQAAAABAAAOwwAAAAAAAYagAACxj//b AEMAAgEBAgEBAgICAgICAgIDBQMDAwMDBgQEAwUHBgcHBwYHBwgJCwkICAoIBwcKDQoKCwwMDAwH CQ4PDQwOCwwMDP/bAEMBAgICAwMDBgMDBgwIBwgMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM DAwMDAwMDAwMDAwMDAwMDAwMDAwMDP/AABEIAl0DjQMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAA AAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEU MoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2Rl ZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK 0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUG BwgJCgv/</p>
  
  <p>.......  (many lines)</p>
  
  <p>Any help is highly appreciated.  </p>
  
  <p>Just in, if someone can tell me some way so that I can send the image as attachment, then also it will be helpful to me.</p>