سؤال

I try to send an email with my python script, but I got the error message:

5.7.0 must issue a starttls command first

I'm using smtplib and this is my code:

import smtplib

sender = 'from@fromdomain.com'
receivers = 'to@todomain.com'

message = """From: From Person <from@fromdomain.com>
To: To Person <to@todomain.com>
Subject: SMTP e-mail test

This is a test e-mail message.
"""

try:
    smtpObj = smtplib.SMTP('smtp.gmail.com')
    smtpObj.sendmail(sender, receivers, message)         
    print "Successfully sent email"
except Exception,e:
    print str(e)

If some one have an idea about how to solve this error I'll be grateful.

هل كانت مفيدة؟

المحلول

GMail won't let random users send mail through their SMTP servers.

As the error says, you'll have to call SMTP.starttls first and authenticate.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top