Skip to main content
 首页 » 编程设计

python之如何使用 python 和 smtplib 阅读电子邮件

2024年08月14日50myhome

发邮件的例子很多,但是收件箱怎么读?例如 yandex。

import smtplib as smtp 
 
email = "me@example.com" 
password = "password" 
 
server = smtp.SMTP_SSL('smtp.yandex.com') 
server.set_debuglevel(1) 
server.ehlo(email) 
server.login(email, password) 
server.auth_plain() 
# server.get_and_print_your_inbox_magic_method() 
server.quit() 

请您参考如下方法:

SMTP protocol用于发送邮件。如果你想查看你的收件箱——也就是接收邮件——你需要使用 POP3或 IMAP .

但就像smtplib , Python也有imaplib用于 IMAP 和 poplib对于 POP3。