-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebug_imap_protocol.py
More file actions
78 lines (61 loc) · 2.38 KB
/
debug_imap_protocol.py
File metadata and controls
78 lines (61 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import imaplib
from config import config
def check_163_security_settings():
"""检查163邮箱的安全设置选项"""
print("=== 检查163邮箱安全设置 ===")
try:
# 连接并尝试各种可能的安全设置
mail = imaplib.IMAP4_SSL('imap.163.com', 993)
# 登录
mail.login(config.MAIL_USERNAME, config.MAIL_PASSWORD)
print("✅ 登录成功")
# 尝试不同的认证方式
print("\n尝试不同的认证方式:")
# 方法1: 标准SELECT
try:
status, data = mail.select('INBOX')
print(f"标准SELECT: {status}")
except Exception as e:
print(f"标准SELECT失败: {e}")
# 方法2: 使用EXAMINE (只读模式)
try:
status, data = mail.examine('INBOX')
print(f"EXAMINE(只读): {status}")
except Exception as e:
print(f"EXAMINE失败: {e}")
# 方法3: 检查其他文件夹
folders = ['INBOX', 'inbox', '收件箱']
for folder in folders:
try:
status, data = mail.select(folder)
print(f"文件夹 '{folder}': {status}")
if status == 'OK':
break
except Exception as e:
print(f"文件夹 '{folder}' 失败: {e}")
mail.logout()
except Exception as e:
print(f"❌ 检查失败: {str(e)}")
def test_alternative_ports():
"""测试其他端口"""
print("\n=== 测试其他端口 ===")
ports = [993, 143, 995] # IMAP SSL, IMAP, POP3 SSL
for port in ports:
print(f"\n测试端口 {port}:")
try:
if port == 993:
mail = imaplib.IMAP4_SSL('imap.163.com', port)
else:
mail = imaplib.IMAP4('imap.163.com', port)
if port == 143:
mail.starttls() # 尝试STARTTLS
mail.login(config.MAIL_USERNAME, config.MAIL_PASSWORD)
print(" ✅ 登录成功")
status, data = mail.select('INBOX')
print(f" 选择INBOX: {status}")
mail.logout()
except Exception as e:
print(f" ❌ 失败: {e}")
if __name__ == "__main__":
check_163_security_settings()
test_alternative_ports()