记一次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之后修改的代码:
import imaplib
def pop3_test(server: str, username: str, password: str):
# 上传身份信息
args = ("name", "YourName", "contact", "your@email.com", "version", "0.0.1", "vendor", "Python.imaplib")
imaplib.Commands['ID'] = ("AUTH") # 防止在使用126/163邮箱途中出现: SELECT Unsafe Login. Please contact kefu@188.com for help
mail = imaplib.IMAP4_SSL(server)
mail.login(username, password)
# 防止在使用126/163邮箱途中出现: SELECT Unsafe Login. Please contact kefu@188.com for help
mail._simple_command('ID', '("' + '" "'.join(args) + '")')
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'))
解决方案参考
- Python使用 imaplib imapclient连接网易邮箱提示 Unsafe Login. Please contact kefu@188.com for help 的解决办法
- Python 163邮箱收邮件报Unsafe Login. Please contact kefu@188.com for help
- imap连接提示Unsafe Login,被阻止的收信行为
- 网易系163、126等邮箱imaplib.search邮件参数该如何设置
- Python的电子邮件处理
--【壹】--:
谢谢佬,最近用龙虾查邮箱遇到了同款问题,放弃之际看到你的贴子,已成功解决
--【贰】--:
都是踩过坑的,也是从网上别人的经验做个汇总,能帮到你就好
最近一个小需求, 需要批量修改某服务的联系邮箱, 提供过来的邮箱又都是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之后修改的代码:
import imaplib
def pop3_test(server: str, username: str, password: str):
# 上传身份信息
args = ("name", "YourName", "contact", "your@email.com", "version", "0.0.1", "vendor", "Python.imaplib")
imaplib.Commands['ID'] = ("AUTH") # 防止在使用126/163邮箱途中出现: SELECT Unsafe Login. Please contact kefu@188.com for help
mail = imaplib.IMAP4_SSL(server)
mail.login(username, password)
# 防止在使用126/163邮箱途中出现: SELECT Unsafe Login. Please contact kefu@188.com for help
mail._simple_command('ID', '("' + '" "'.join(args) + '")')
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'))
解决方案参考
- Python使用 imaplib imapclient连接网易邮箱提示 Unsafe Login. Please contact kefu@188.com for help 的解决办法
- Python 163邮箱收邮件报Unsafe Login. Please contact kefu@188.com for help
- imap连接提示Unsafe Login,被阻止的收信行为
- 网易系163、126等邮箱imaplib.search邮件参数该如何设置
- Python的电子邮件处理
--【壹】--:
谢谢佬,最近用龙虾查邮箱遇到了同款问题,放弃之际看到你的贴子,已成功解决
--【贰】--:
都是踩过坑的,也是从网上别人的经验做个汇总,能帮到你就好

