如题,求助。谢谢!
#!/usr/bin/python
-*- coding: UTF-8 -*-
import os, sys, string
import poplib
pop3服务器地址
pop_server_host = "pop.qq.com"
用户名
email_address = "aaaaa@qq.com"
密码
email_password = "bbbbbbb"
端口
pop_server_port = 995
创建一个pop3对象,这个时候实际上已经连接上服务器了
try:
# 连接pop服务器。如果没有使用SSL,将POP3_SSL()改成POP3()即可其他都不需要做改动
email_server = poplib.POP3_SSL(host=pop_server_host, port=pop_server_port, timeout=10)
print("pop3----connect server success, now will check username")
except:
print("pop3----sorry the given email server address connect time out")
exit(1)
try:
# 验证邮箱是否存在
email_server.user(email_address)
print("pop3----username exist, now will check password")
except:
print("pop3----sorry the given email address seem do not exist")
exit(1)
try:
# 验证邮箱密码是否正确
email_server.pass_(email_password)
print("pop3----password correct,now will list email")
except:
print("pop3----sorry the given username seem do not correct")
exit(1)
# 邮箱中其收到的邮件的数量
email_count = len(email_server.stat())
# 通过retr(index)读取第index封邮件的内容;这里读取最后一封,也即最新收到的那一封邮件
#resp, lines, octets = email_server.retr(email_count)
# lines是邮件内容,列表形式使用join拼成一个byte变量
#email_content = b'\r\n'.join(lines)
# 再将邮件内容由byte转成str类型
#email_content = email_content.decode()
print(email_count)
# 关闭连接
email_server.close()