Python 3 | Send Email - SMTP - gmail - Error: SMTPException

I want to send an email using Python 3. I still can not understand the examples that I saw. Here is one link: Using Python to send email

I pulled out the first simple example found in the link above. I find this example a good example of a combination of examples that I have seen on the Internet. This is apparently the main form of what I am doing.

When I try to execute the code below, I get an error:

File "C:\Python33\Lib\email.py", line 595, in login raise SMTPException("SMTP AUTH extension not supported by server.") smtplib.SMTPException: SMTP AUTH extension not supported by server. 

Here is the code:

 # Send Mail import smtplib server = smtplib.SMTP('smtp.gmail.com', 587) # Log in to the server server.login(" myEmail@gmail.com ","myPassword") # Send mail msg = "\nHello!" server.sendmail(" myEmail@gmail.com "," recipient@gmail.com ", msg) 
+4
source share
2 answers

I found a solution on YouTube.

Here's a link .

 # smtplib module send mail import smtplib TO = ' recipient@mailservice.com ' SUBJECT = 'TEST MAIL' TEXT = 'Here is a message from python.' # Gmail Sign In gmail_sender = ' sender@gmail.com ' gmail_passwd = 'password' server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.login(gmail_sender, gmail_passwd) BODY = '\r\n'.join(['To: %s' % TO, 'From: %s' % gmail_sender, 'Subject: %s' % SUBJECT, '', TEXT]) try: server.sendmail(gmail_sender, [TO], BODY) print ('email sent') except: print ('error sending mail') server.quit() 
+17
source

As of mid-October 2017, gmail does not accept connections through smtplib.SMTP() on port 587 , but requires smtplib.SMTP_SSL() and port 465 . It starts immediately with TLS , and ehlo not required. Instead, try this snippet:

 # Gmail Sign In gmail_sender = ' sender@gmail.com ' gmail_passwd = 'password' server = smtplib.SMTP_SSL('smtp.gmail.com', 465) server.login(gmail_sender, gmail_passwd) # build and send the email body. 
+2
source

Source: https://habr.com/ru/post/1488390/


All Articles