title: Sending XML content with smtplib in Python 3
body: <p>I am trying to send XML content using <code>smtplib</code> in <code>python3</code>.  </p>
  
  <p>Below is my code:  </p>
  
  <pre><code>#!/usr/bin/python
  
  
  import smtplib
  import os
  
  fromAddress = "adipratapsingh.aps@gmail.com"
  toAddress = "adirameshwarsingh.ars@gmail.com"
  
  msg = "From: Aditya Thakur&lt;"+fromAddress+"&gt;\r\n"
  msg = msg + "To: Aditya Singh&lt;"+toAddress+"&gt;\r\n"
  msg = msg + "Reply-To: Aditya Thakur&lt;"+fromAddress+"&gt;\r\n"
  msg = msg + "Content-Type: text/xml\r\n"
  msg = msg + "Subject: Python mail\r\n"
  msg = msg + "\r\n"
  msg = msg + """
  &lt;xml version="1.0" encoding="utf-8"&gt;
  &lt;Name&gt;
      &lt;Firstname&gt;Aditya&lt;/Firstname&gt;
      &lt;Middlename&gt;Rameshwarpratap&lt;/Middlename&gt;
      &lt;Lastname&gt;Singh&lt;/Lastname&gt;
  &lt;/Name&gt;  
  """
  
  server = smtplib.SMTP("smtp.gmail.com:587")
  server.starttls()
  server.login(fromAddress, os.getenv("GMAIL_APP_PASSWORD"))
  server.sendmail(fromAddress, toAddress, msg)
  server.quit()
  </code></pre>
  
  <p>This code works fine with normal text mail and HTML mail. I also am able to send XML content to the client.  </p>
  
  <p>But the thing is that this XMl content is sent as a file(attachment) by the name "noname" and I am not able to specify any filename for it. It goes by the name "noname" without any extension. And so, my client is not even able to view it without renaming it to "noname.xml". Is there any way I can specify a name for my XML file I am sending?  </p>
  
  <p>Secondly, When my client renames the file to "noname.xml", an error pops up in the browser that says  </p>
  
  <pre><code>"There are some extra characters at line 8 column 1. Extra content at the end of the document."  
  </code></pre>
  
  <p>Why is that?</p>
  
  <p>NOTE: I want to use <code>smtplib</code> and nothing else.</p>