【问题标题】:Python3 Sending Email with Smtplib [Yandex]Python3 使用 Smtplib [Yandex] 发送电子邮件
【发布时间】:2018-12-09 13:42:09
【问题描述】:

我正在尝试使用 yandex 发送电子邮件,但我的功能不起作用。它只是永远等待,也没有错误。这是我的功能:

def send_emails(title,msg):
    server = smtplib.SMTP('smtp.yandex.com.tr:465')
    server.ehlo()
    server.starttls()
    server.login(yandex_mail,yandex_pass)
    message = 'Subject: {}\n\n{}'.format(title,msg)
    server.sendmail(yandex_mail,send_to_email,message)
    server.quit()
    print('E-mails successfully sent!')

send_emails('Test Mail', 'Yes its a test mail!')

【问题讨论】:

    标签: python python-3.x smtp smtp-auth


    【解决方案1】:

    我认为你的问题在这里:

    server = smtplib.SMTP('smtp.yandex.com.tr:465')
    

    您需要使用smtplib.SMTP_SSL,因为与SSL docs 的连接是安全的,而且smtplib.SMTP_SSL 获得许多参数,第一个是host,第二个是port 和其他参数,但您现在只需要这两个,需要分别给hostport,试试这个

    def send_emails(title,msg):
        server = smtplib.SMTP_SSL('smtp.yandex.com.tr', 465)
        ...
    

    【讨论】:

    • 什么都没有改变它仍然在等待永远。
    • 但没有 tr ?仅限smtp.yandex.com
    • 我尝试了两种相同的行为。我发现了老问题:stackoverflow.com/questions/39516200/… - 但也没有解决方案
    • 尝试在server.starttls() 之后放置另一个server.ehlo()
    • 我更新我的答案尝试使用smtplib.SMTP_SSL('smtp.yandex.com', 465),重要的是smtplib.SMTP_SSL(),如果我在此之后打印出任何东西,它会起作用
    猜你喜欢
    • 1970-01-01
    • 2015-09-07
    • 2021-04-26
    • 1970-01-01
    • 2014-01-31
    • 1970-01-01
    • 2015-03-06
    • 2019-06-19
    • 2011-09-17
    相关资源
    最近更新 更多