Python3 使用 Smtplib 发送电子邮件 [Yandex]
Python3 Sending Email with Smtplib [Yandex]
我正在尝试使用 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!')
我认为你的问题出在这里:
server = smtplib.SMTP('smtp.yandex.com.tr:465')
你需要使用smtplib.SMTP_SSL because connection is security with SSL
docs,还有smtplib.SMTP_SSL
得到很多参数,第一个是host
,第二个是port
和其他参数,但你现在只需要这个二、需要分别给host
和port
,试试这个
def send_emails(title,msg):
server = smtplib.SMTP_SSL('smtp.yandex.com.tr', 465)
...
我正在尝试使用 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!')
我认为你的问题出在这里:
server = smtplib.SMTP('smtp.yandex.com.tr:465')
你需要使用smtplib.SMTP_SSL because connection is security with SSL
docs,还有smtplib.SMTP_SSL
得到很多参数,第一个是host
,第二个是port
和其他参数,但你现在只需要这个二、需要分别给host
和port
,试试这个
def send_emails(title,msg):
server = smtplib.SMTP_SSL('smtp.yandex.com.tr', 465)
...