restshoes.blogg.se

Sending an email with an pdf attachment using smtp command
Sending an email with an pdf attachment using smtp command









Sender_name, sender_addr = parseaddr(sender) # Split real name (which is optional) and email address parts Print("Could not encode " + body + " as " + charset + ".") # Testing if body can be encoded with the charset Here's the code, for Python 3: #!/usr/bin/env python3įrom import MIMEMultipartįrom email.utils import parseaddr, formataddr Send yourself an e-mail, save it and examine the content to figure out how to do the same thing in Python. There probably exists a function that can do this. Non-ascii characters in replyto needs to be encoded with, for instance, ISO-8859-1. It was not straightforward to figure this one out, due to lack of documentation and samples for this particular case. Here's how to send e-mails with zip file attachments and utf-8 encoded subject+body. import smtplib,email,email.encoders,ĮmailMsg = ('alternative')ĮmailMsg.attach((html,'html'))įileMsg = ('application','vnd.ms-excel')įt_payload(file('exelFile.xls').read())įileMsg.add_header('Content-Disposition','attachment filename=anExcelFile.xls') It creates an HTML email with an Excel attachment. Here's an example I snipped out of a work application we did. # So, I use the default port 25, but I authenticate. # port 25 packets to be port 587 and it is trashing port 587 packets.

sending an email with an pdf attachment using smtp command

# NOTE: my ISP, Centurylink, seems to be automatically rewriting This is a rather nice letter, don't you think?""")Ītt = (fp.read(),_subtype="pdf")Ītt.add_header('Content-Disposition','attachment',filename=filename) Msg = The main body is just another attachmentīody = ("""Hello, how are you? I am fine. # Import smtplib for the actual sending function

sending an email with an pdf attachment using smtp command

Here is an example of a message with a PDF attachment, a text "body" and sending via Gmail.











Sending an email with an pdf attachment using smtp command