Ok, so I'm following the sample code at the Python docs for sending a simple basic email. I even created a textfile with a message in it. Anyway, I'm doing it in the Python interpreter via ssh to test it out & make sure I know what I'm doing, but when I press enter after typing the s.send_message(msg) line, I get this surprising TypeError:
import smtplib from email.mime.text import MIMEText textfile = 'txt4mail.txt' fp = open(textfile,'rb') msg = MIMEText(fp.read()) fp.close() msg['Subject'] = "Sent using Python 3" msg['From'] = 'firstname.lastname@example.org' msg['To'] = 'email@example.com' s = smtplib.SMTP('smtp.webfaction.com') s.send_message(msg)
I come from a PHP background & have only been learning Python for a few months, so I'm not sure what's causing the error in such a basic thing. Shouldn't the example code "just work"? So, what's going on here that I need to fix? Is there a server setting I might be unaware of? Is it possible that something I put in the textfile is causing it? I tried changing stuff in it but it didn't seem to have any affect. I'm really confused.
The textfile I created in vi, is simply this, nothing special --
Yo dude! I am sending this via Py3k. Test link: http://google.com, enjoy! - Yourself