Sending Email in Python -


i'm trying send basic email using python 3.3. i'm following first bit of code here:

https://docs.python.org/3.3/library/email-examples.html 

my code follows:

def emailcurrentrankings(recipientemail):     fp = open('rankings.txt', 'rb')     msg = mimetext(fp.read())     fp.close()      sender = 'bclayman@gmail.com'     msg['subject'] = 'csa rankings'     msg['from'] = sender     msg['to'] = recipientemail      s = smtplib.smtp('localhost')     s.sendmail(sender, [recipientemail], msg.as_string())     s.quit() 

my main function calls method so:

emailcurrentrankings('bclayman@gmail.com') 

the difference can tell use 'rankings.txt' instead of textfile on second line. i've tried both , same error message:

traceback (most recent call last):   file "helpfulfunctions.py", line 128, in <module>     main()   file "helpfulfunctions.py", line 120, in main     emailcurrentrankings('bclayman@gmail.com')   file "helpfulfunctions.py", line 106, in emailcurrentrankings     msg = mimetext(fp.read())   file "/library/frameworks/python.framework/versions/3.3/lib/python3.3/email/mime/text.py", line 34, in __init__     _text.encode('us-ascii') attributeerror: 'bytes' object has no attribute 'encode' 

when googled around, looks there's authentication has happen (for me able send given email). basic example i'm modeling code on doesn't mention this...

any ideas i'm going astray?

thanks, bclayman

try openning file without without using binary format.

maybe -

fp = open('rankings.txt', 'r') 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -