i am trying come send email (Gmail) making use of python, but I to be getting adhering to error.

Você está assistindo: Como enviar um email pelo gmail

Traceback (most recent contact last): record "emailSend.py", heat 14, in server.login(username,password) file "/usr/lib/python2.5/smtplib.py", line 554, in conecte-se raise SMTPException("SMTP AUTH extension not sustained by server.") smtplib.SMTPException: SMTP AUTH extension not sustained by server.The Python roteiro is ns following.

import smtplibfromaddr = "user_me
gmail.com"password = "pwd"server = smtplib.SMTP("smtp.gmail.com:587")server.starttls()server.login(username,password)server.sendmail(fromaddr, toaddrs, msg)server.quit()



def send_email(user, pwd, recipient, subject, body): income smtplib em ~ = user to = recipient if isinstance(recipient, list) rather topic = subject TEXT = body # Prepare actual message message = """From: %s To: %s Subject: %s %s """ % (FROM, ", ".join(TO), SUBJECT, TEXT) try: server = smtplib.SMTP("smtp.gmail.com", 587) server.ehlo() server.starttls() server.login(user, pwd) server.sendmail(FROM, TO, message) server.close() publish "successfully sent the mail" except: print "failed to send mail"if you want to use Port 465 you have to produce an SMTP_SSL object:

# SMTP_SSL Exampleserver_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465)server_ssl.ehlo() # optional, dubbed by login()server_ssl.login(gmail_user, gmail_pwd) # ssl server doesn"t assistance or require tls, so don"t call server_ssl.starttls() server_ssl.sendmail(FROM, TO, message)#server_ssl.quit()server_ssl.close()print "successfully sent the mail"
improve this answer
edited might 9 "18 in ~ 17:46


Brad Solomon
32.3k2424 gold badges113113 silver- badges196196 cobre badges
answered Sep 14 "12 in ~ 12:19

david OkwiiDavid Okwii
6,60522 yellow badges3030 silver- badges2727 cobre badges
| show 7 more comments
You should say EHLO before just to run straight right into STARTTLS:

server = smtplib.SMTP("smtp.gmail.com:587")server.ehlo()server.starttls()Also you must really create From:, To: e Subject: blog post headers, separated em ~ the message corpo humano by der blank line and use CRLF together EOL markers.


msg = " ".join(< "From: user_me
gmail.com", "To: user_you
gmail.com", "Subject: Just der message", "", "Why, oh why" >)Note:

In order for this to work you require to enable "Allow much less secure apps" choice in her gmail account configuration. Otherwise you will get der "critical defense alert" as soon as gmail detects that naquela non-Google apps is do the efforts to login your account.

boost this prize
edited Dec 22 "20 at 14:59

14.7k55 yellow badges3535 silver- badges5858 cobre badges
answer Apr 13 "12 at 19:57
34.4k1010 gold badges8080 silver badges8484 cobre badges
| show 13 more comments
I ran into naquela similar problem and stumbled ~ above this question. I obtained an SMTP Authentication Error but my user name / pass era correct. Here is what addressed it. I read this:


In a nutshell, google is not permitting you to log in in através da smtplib due to the fact that it has flagged this kind of inscrever-se as "less secure", for this reason what you have to a partir de is go to this link while you"re logged in come your google account, e allow a access:


Once the is collection (see mine screenshot below), it have to work.

Ver mais: Como Declarar Imposto De Renda Pela Primeira Vez 2018, Vai Fazer A Declaraã§Ã£O Do Ir Pela Primeira Vez


Login agora works:

smtpserver = smtplib.SMTP("smtp.gmail.com", 587)smtpserver.ehlo()smtpserver.starttls()smtpserver.ehlo()smtpserver.login("me
gmail.com", "me_pass")Response after ~ change:

(235, "2.7.0 Accepted")Response prior:

smtplib.SMTPAuthenticationError: (535, "5.7.8 Username and Password no accepted. Learn an ext at 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 g66sm2224117qgf.37 - gsmtp")Still no working? If girlfriend still importar the SMTPAuthenticationError but now the code is 534, the because ns location is unknown. Follow this link:


Click continue and this should offer you 10 minutes ao registering your novo app. So continue to act another conecte-se attempt now and it have to work.

UPDATE: This doesn"t it seems ~ to work-related right longe you may be grounding for der while gaining this error in smptlib:

235 == "Authentication successful"503 == "Error: already authenticated"The post says come use the browser to authorize in:

SMTPAuthenticationError: (534, "5.7.9 you re welcome log in with your internet browser and then try again. Learn more at 5.7.9 https://support.google.com/mail/bin/answer.py?answer=78754 qo11sm4014232igb.17 - gsmtp")After enabling "lesssecureapps", walk for der coffee, come back, e try ns "DisplayUnlockCaptcha" attach again. Em ~ user experience, the may take up come an hour ao the mudança to absent in. Then try ns sign-in process again.