pythonemailsmtpsmtplibyahoo-mail

Send email using my yahoo account - error message


I use Python 3.5.2.

I am trying to use my yahoo account to send email. I use the yahoo SMTP server domain name smtp.mail.yahoo.com according to this website `http://neerajbyte.com/send-email-through-python-console-with-gmail-hotmail-and-yahoo/'. However I got an error message (below). Normally for security reasons google, I tried it, would send me an email notifying me of an application trying to access my account and I have to click on a link to allow it. But I didn't get an email from yahoo but just this error message, not sure why.

this is my code:

>>> import smtplib
>>> conn = smtplib.SMTP('smtp.mail.yahoo.com', 587)
>>> type(conn)
<class 'smtplib.SMTP'>
>>> conn
<smtplib.SMTP object at 0x02AD9A70>
>>> conn.ehlo()
(250, b'smtp.mail.yahoo.com\nPIPELINING\nSIZE 41697280\n8 BITMIME\nSTARTTLS')
>>> conn.starttls
<bound method SMTP.starttls of <smtplib.SMTP object at 0x02AD9A70>>
>>> conn.login('j@yahoo.com', 'j2')

this is my error message:

_Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    conn.login('j@yahoo.com', 'j2')
  File "C:\Users\J\AppData\Local\Programs\Python\Python35-32\lib\smtplib.py", line 696, in login
    "SMTP AUTH extension not supported by server.")
smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.
_

Solution

  • To my knowledge, Yahoo and Gmail expect 2-factor authentication when trying to login from apps. These are the steps:

    1. In Yahoo, you can go to Account Info.

    2. Click on the Account Security tab on the left. Enable 2-step verification. I then first time you try this you will get options to select the method of verification. Usually I choose OTP via SMS.

    3. Then you can Manage App Passwords. This will bring up a popup to generate a 16-character password. This is what you can use from your app when logging into your mail.

    Below is a sample screenshot: enter image description here