Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29758

Changing Attachment Header MIME python

$
0
0

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?

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)

EDIT

This is the file heading that is attached:

enter image description here


Viewing all articles
Browse latest Browse all 29758

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>