记一次Python(imaplib)读取邮件(126163)时出现"SELECT Unsafe Login"错误解决
- 内容介绍
- 文章标签
- 相关推荐
最近一个小需求, 需要批量修改某服务的联系邮箱, 提供过来的邮箱又都是126/163邮箱.
需求是登录原账号, 修改邮箱, 需要用新的邮箱接收验证码, 由于需要批量修改, 使用Playwright进行处理, 但在测试imap收信时出现了以下问题:
SELECT Unsafe Login. Please contact kefu@188.com for help
一顿摸索, 还是在茫茫google数据库中找到了解决方案.
| 原代码:
import imaplib
def pop3_test(server: str, username: str, password: str):
mail = imaplib.IMAP4_SSL(server)
mail.login(username, password)
try:
status, messages = mail.select('INBOX') # 选择收件箱
# print(status, messages)
except BaseException as e:
print(f'error: {e}')
# 获取所有未读的邮件UID
typ, data = mail.search(None, 'SUBJECT hello')
msg_id = data[0].decode('utf-8')
typ, msg_data = mail.fetch(msg_id, 'BODY[TEXT]')
print(msg_data[0][1].decode('utf-8'))
出现SELECT Unsafe Login. Please contact kefu@188.com for help之后修改的代码:
最近一个小需求, 需要批量修改某服务的联系邮箱, 提供过来的邮箱又都是126/163邮箱.
需求是登录原账号, 修改邮箱, 需要用新的邮箱接收验证码, 由于需要批量修改, 使用Playwright进行处理, 但在测试imap收信时出现了以下问题:
SELECT Unsafe Login. Please contact kefu@188.com for help
一顿摸索, 还是在茫茫google数据库中找到了解决方案.
| 原代码:
import imaplib
def pop3_test(server: str, username: str, password: str):
mail = imaplib.IMAP4_SSL(server)
mail.login(username, password)
try:
status, messages = mail.select('INBOX') # 选择收件箱
# print(status, messages)
except BaseException as e:
print(f'error: {e}')
# 获取所有未读的邮件UID
typ, data = mail.search(None, 'SUBJECT hello')
msg_id = data[0].decode('utf-8')
typ, msg_data = mail.fetch(msg_id, 'BODY[TEXT]')
print(msg_data[0][1].decode('utf-8'))
出现SELECT Unsafe Login. Please contact kefu@188.com for help之后修改的代码:

