Error Sending Email (gmail) Via Python 2.6
This one has been baffling me for a while. Can anyone see where i'm going wrong? This code works fine in Python 2.7; however, it breaks when running through a cron (Python 2.6). de
Solution 1:
I've finally got it to work. It turns out I just needed to add a couple of extra lines:
server.ehlo()
server.starttls()
server.ehlo()
Therefore, the final script goes:
def send_email (message, status):
fromaddr = 'sam@gmail.com'
toaddrs = 'sam@gmail.com'
server = SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('username-example', 'password-example')
server.sendmail(fromaddr, toaddrs, 'Subject: %s\r\n%s' % (status, message))
server.quit()
send_email('message text','subject text')
Post a Comment for "Error Sending Email (gmail) Via Python 2.6"