Dig up this for discussion thread request and some Googling. By little experiment found the different forms for sending message commands. Could no send in Python3 the code of program itself so only simple test "Hello". Sorry that subject is left incorrectly refering program name.
Python 3 and Python 2 send email through gmail
JoshuaBurleson commented: Thanks Tony! +3
# thanks to http://segfault.in/2010/12/sending-gmail-from-python/
import sys
# Import smtplib for the actual sending function
import smtplib
try:
input = raw_input
except:
pass
# Import the email modules we'll need
from email.mime.text import MIMEText
# Create a text/plain message
msg = MIMEText("Hello from Python%s\n" % sys.version)
msg['Subject'] = 'The contents of %s' % sys.argv[0]
msg['From'], msg['To'] = "xxx@gmail.com", "yyy@gmail.com"
# Send the message via gmail SMTP server
s = smtplib.SMTP('smtp.gmail.com', 587)
s.ehlo()
s.starttls()
s.login(msg['From'], input('Password: '))
try:
# Python 3.2.1
s.send_message(msg)
except AttributeError:
# Python 2.7.2
s.sendmail(msg['From'], [msg['To']], msg.as_string())
s.quit()
JoshuaBurleson 23 Posting Whiz
Tech B 48 Posting Whiz in Training
JoshuaBurleson commented: Also, obviously, works great for subject-less emails +3
JoshuaBurleson 23 Posting Whiz
TrustyTony 888 pyMod Team Colleague Featured Poster
sureronald 0 Junior Poster
woooee 814 Nearly a Posting Maven
JoshuaBurleson 23 Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.