Sending an email with a binary attachment
pkpearson at nowhere.invalid
Mon Feb 29 12:08:32 EST 2016
On Mon, 29 Feb 2016 02:10:00 -0600, Anthony Papillion wrote:
To improve odds of your getting a response, let's get the code
into this thread. Here it is, minus the #! preamble:
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP
FILE_TO_SEND = "/home/anthony/Desktop/passwords.kdb"
message = MIMEMultipart()
message['Subject'] = 'Password database update'
message['From'] = 'Database Update Script <xxx at cajuntechie.org'
message['reply-to'] = 'xxx at cajuntechie.org'
message['to'] = 'Me <xxx at cajuntechie.org'
message.preamble = 'Multipart massage.\n'
part = MIMEText("Attached is the latest update to the password database.")
part = MIMEApplication(open(FILE_TO_SEND, "rb").read())
filename = FILE_TO_SEND)
smtp = SMTP("smtp.zoho.com", 587)
smtp.login("xxxx at cajuntechie.org", "my_password")
print "Message sending has failed"
print "Message sending was successful"
> For some reason though, sending mail is failing every time. I've made
> sure that the password is correct (which seems to be the most usual
> Still, I just can't get it to work. Can someone take a look at this
> code and give me some advice?
What exactly do you mean by "failing"? If there's an error message,
show it. If an exception is being generated, at least print some
information about the exception.
To email me, substitute nowhere->runbox, invalid->com.
More information about the Python-list