Yuzayu Python 3.4.3. I want to write a simple script that text information will be sent to a specified box. Found: The following example . In the interpreter mode I enter:
& gt; & gt; & gt; Import SMTPLIB
& gt; & gt; & gt; Server = SMTPLib.SMTP ('smtp.yandex.ru', 465)
And on the second line, the interpreter is tightly hanging. For Yandex Info About server took hence .
UPD: If you use the same for Gmail:
server = smtplib.smtp ('smtp.gmail.com', 587)
That is all the rules. However, I want (i.e. there is a box) connect to Yandex. Maybe it?
UPD2: If the port is 587 for Yandex, the second line also passes. However, the third:
server.login ("youremailusername", "password")
leads to a raise of exhepn smtplib.smtpserverdisconnected
udp3: found This question is . I do this:
import smtplib
SMTP = SMTPLIB.SMTP_SSL ()
SMTP.CONNECT ('SMTP.YANDEX.RU')
and falls out ssl.ssleoferror
UPD4: found This link and did this:
server = smtplib.smtp_ssl ('smtp.yandex.ru:465')
Server.login ('Login', 'Pass')
And everything worked. It worked in the sense that it came smtplib.smtpauthenticationerror
with the message, the essence of which is what I behave like a robot and I need to tie the mobile number to stop seeing the robot in me. Apparently, protecting the password selection.
Answer 1, Authority 100%
For Yandex I managed to go through Authentication Auth Plain via SSL connection.
This code works:
#! / usr / bin / env python3
Import SMTPLIB AS SMTP
from GetPass Import GetPass
Email = Input ('Enter Mail: \ N')
Password = GetPass ('Enter the password:')
DEST_EMAIL = INPUT ('Enter the recipient's address: \ n')
subject = input ('letter topic: \ n')
email_text = input ('Letter text: \ n')
Message = 'from: {} \ Nto: {} \ NSubject: {} \ n \ n {}'. Format (Email,
DEST_EMAIL,
Subject
email_text)
Server = SMTP.SMTP_SSL ('smtp.yandex.com')
server.set_debuglevel (1)
Server.ehlo (Email)
Server.login (Email, Password)
Server.auth_plain ()
Server.Sendmail (Email, Dest_Email, Message)
server.quit ()
Answer 2, Authority 33%
@xyanight (I hope I called him): for gmail
import smtplib
DEF SENDEMAIL (Text):
Server = SMTPLIB.SMTP ("smtp.gmail.com", 587)
Server.ehlo ()
Server.StartTls ()
Server.login ("Login", "Pass")
Message = "\ R \ n" .join ([
"From: from whom",
"To: to whom"
"SUBJECT: theme",
"",
STR (Text)
])
Server.sendmail ("From whom", "To", Message)
server.quit ()
Answer 3
I have it so much for Yandex:
import smtplib
email = '[email protected]'
password = 'some_pass'
Server = SMTPLib.SMTP ('smtp.yandex.ru', 587)
Server.ehlo () # By the way, why is it?
Server.StartTls ()
Server.login (Email, Password)
Dest_Email = '[email protected]'
subject = 'Booking from Chatbot'
email_text = 'TEXT'
Message = 'From:% S \ NTO:% S \ NSubject:% S \ N \ N% s'% (Email, Dest_Email, Subject, email_text)
Server.set_debuglevel (1) # Optionally; So the data from the server in the console will be displayed.
Server.Sendmail (Email, Dest_Email, Message)
server.quit ()