Home python How to send an email with Python?

How to send an email with Python?




Tell me, it took on Python to send a message to Yandex mail.
I found the code, but the error crashes.
Read, it is written that the error can fly, since the password may not be in the utf-8 encoding.
I write in the code for Password, addr_from, addr_to it is: encode (encoding = ‘utf-8’) – zero emotions.
Tell me how then fix the error?

import smtplib # Import library to work with SMTP
# Add the necessary subclasses - Mime-types
from email.mime.multipart import mimemultipart # multicomponent object
from email.mime.text Import MimeText # text / HTML
ADDR_FROM = "[email protected]"
ADDR_TO = "[email protected]"
Password = "Pass" # password from the mail addr_from
MSG = Mimemultipart () # Create a message
msg ['from'] = addr_from # addressee
msg ['to'] = addr_to # recipient
MSG ['SUBJECT'] = 'Message topic' # Message topic
Body = "Message Text"
MSG.attach (Body, 'Plain')) # add text to message
Server = smtplib.smtp_ssl ('smtp.yandex.ru', 465) # Create an SMTP object
# server.starttls () # start encrypted TLS exchange
Server.login (Addr_From, Password) # Get Access
Server.send_Message (MSG) # send a message
server.quit () # come out


smtplib.smtpauthenticationerror: (535, b'5.7.8 Error: Authentication Failed: This User Does Not Have Access Rights to this service ')

Answer 1, Authority 100%

just had an identical error with postcase on Yandex for local Hitlab. Based on the googling, usually associated with the use of features disconnected in the Yandex account settings.

In my case, it was helped to enable the “Portal Password” option.

Path to option:

  1. Click on the gear icon in the upper right corner
  2. in the drop-down menu: “Other”
  3. on the new page in the list on the left Select “Postal Programs”
  4. Put a checkbox on a checkbox “Portal Password”

Answer 2, Authority 100%

was the same problem, here the answer – https://searchengines.guru/ru/forum/1037543 .

Configure the box you need:

tried everyone, the decision was not obvious – helped
Prostanovka check box in the settings of the box from which is carried out
Departure: Mail- & gt; All settings – & gt; Postal programs

Allow access to the mailbox using postal clients, section
IMAP, I put all the daws there, including in the POP3 section


Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions