title: Changing Attachment Header MIME python
body: <p>I have attempted to change the header of my attached pdf from the default "noname" to some other header. Unfortunately the following "add_header" part of my code doesn't change the actual header name. Are there any alternatives without corrupting or altering the contents of the attached file?</p>
  
  <pre><code>fromaddr = 'XXXXX@gmail.com'  
  toaddrs  = 'XXXXX@gmail.com'
  
  username = 'XXXX'  
  password = 'XXXXX'
  msg = MIMEMultipart()
  msg['Subject']='Spam'
  
  msg.preamble = 'SDFSFSDF'
  
  
  file=open(r'XXXXXX.pdf','rb').read()
  
  msg.attach(MIMEApplication(file,'pdf'))
  
  msg.add_header('XXXXXX', 'file', filename = 'XXXXXX.pdf')
  
  server = smtplib.SMTP('smtp.gmail.com', 587)  
  server.ehlo()
  server.starttls()
  server.login(username, password)  
  server.sendmail(fromaddr, toaddrs, msg.as_string())  
  time.sleep(2)
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is the file heading that is attached:</p>
  
  <p><a href="https://i.stack.imgur.com/hNOzt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hNOzt.png" alt="enter image description here"></a></p>