title: TIdMessage - Attachments Show Up in Body as Base64
body: <p>I'm working on sending emails via SMTP using the Indy components (<code>TIdMessage</code>). Such an email needs to be HTML, and needs to carry attachments.</p>
  
  <p>Now if I send an email as plain text (<code>ContentType := 'text/plain'</code>), and attach a file, the email sends just fine, attachment found and everything.</p>
  
  <p>However, once I change the <code>ContentType</code> to <code>text/html</code>, I have a very bizarre result. The entire body of the email gets replaced with apparently the underlying email data (in my words), and shows the attachment in the body as Base64 data.</p>
  
  <p>For example, here's just the first few lines of such a resulting email:</p>
  
  <pre>
  This is a multi-part message in MIME format
  
  --YGuFowdSjNaa=_khosBzZl5L8uGVtfasBX
  Content-Type: text/plain; charset="us-ascii"
  Content-Transfer-Encoding: quoted-printable
  Content-Disposition: inline
  
  This is the body of a test email.
  --YGuFowdSjNaa=_khosBzZl5L8uGVtfasBX
  Content-Type: application/octet-stream; name="TagLogo.jpg"
  Content-Transfer-Encoding: base64
  Content-Disposition: inline; filename="TagLogo.jpg"
  
  /9j/4AAQSkZJRgABAQEASwBLAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcU
  FhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgo
  KCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCADhAG8DASIA
  AhEBAxEB/8QAHAAAAgMBAQEBAAAAAAAAAAAAAAcFBggEAgED/8QAPxAAAQIFAwEEBwYFAwQDAAAA
  AQIDAAQFBhEHEiExCBNBdSI3OFFhsrMUMkJxgZEVIzNSgmJyoRaSosEk0eH/xAAWAQEBAQAA
  </pre>
  
  <p>Although the original body was only</p>
  
  <pre><code>This is the body of a test email.
  </code></pre>
  
  <p>The code is very simple, matching all the examples I can find online...</p>
  
  <pre><code>IdMessage.Charset := 'UTF-8';
  IdMessage.ContentType := 'text/html'; // &lt;-- text/plain works fine.....
  IdMessage.Body := 'This is the body of a test email.';
  
  ... (Assigning Other Unrelated Properties) ...
  
  A := TIdAttachmentFile.Create(IdMessage.MessageParts, 'C:\SomeFile.jpg'); // &lt;-- Originally the only LOC here
  A.ContentTransfer := 'base64'; // &lt;-- Tried with and without
  A.ContentType := 'application/octet-stream'; // &lt;-- Tried with and without
  //A.ContentType := 'image/jpeg'; // &lt;-- Tried with and without
  A.ContentDisposition := 'inline'; // &lt;-- Tried with and without
  </code></pre>
  
  <p>Why is this resulting in a "garbage" email, and how do I solve it while supporting HTML email body with attachments?</p>
  
  <p>PS - If it makes any difference, the attachments will be images used in-line in the email body in the end. </p>