Отправка электронной почты с smtplib - PullRequest
0 голосов
/ 25 марта 2020
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def sendmail(from_email, password, to_email, subject, message):
    msg = MIMEMultipart()
    msg['From'] = from_email
    msg['To'] = to_email
    msg['Subject'] = subject

    msg.attach(MIMEText(message, 'plain'))
    try:
        server = smtplib.SMTP_SSL('smtp.outlook.com', 465)
        server.ehlo()
        server.login(from_email, password)
        server.sendmail(from_email, to_email, msg.as_string())
        server.close()
        return True
    except Exception as e:
        print('Something went wrong: ' + str(e))
        return False

sendmail('myname@mycompanyname.com.tr', 'mypassword', 'myworkmatename@mycompanyname.com.tr', 'TEST', 'I send a mail to you with Python')

Я получаю эту ошибку:

[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Я видел некоторые решения о настройках прокси, но у меня это не работает. Как я могу это исправить?

...