我试图使用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 因为连接是安全的 SSL docs ,同时 smtplib.SMTP_SSL 得到许多参数,首先是 host 其次是 port 还有其他的参数,但你现在只需要这两个,你需要 主办 和 港口 另外,试试这个
SSL
smtplib.SMTP_SSL
host
port
主办
港口
def send_emails(title,msg): server = smtplib.SMTP_SSL('smtp.yandex.com.tr', 465) ...