I'm currently working on an app where I need to retrieve emails from mail.com or any similar service. I'm trying mail.com though. I have searched and tried almost a lot of solutions available online but nothing seems to work on any service. I have tried to log in to yahoo.com, mail.ru, and mail.com, etc with the same code and all of them gave the same error. This is the code I'm using to log in to mail.com.
import imaplib
import pprint
imap_host = 'imap.mail.com'
imap_user = '[email protected]'
imap_pass = 'password'
# connecting to host via SSL
imap = imaplib.IMAP4_SSL(imap_host)
print(imap.port)
print("Connected to server.")
print(imap.welcome)
# logging in to servers
imap.login(imap_user, imap_pass)
print("Login complete.")
# Selecting the inbox of the logged in account
imap.select('Inbox')
tmp, data = imap.search(None, 'ALL')
for num in data[0].split():
tmp, data = imap.fetch(num, '(RFC822)')
print('Message: {0}\n'.format(num))
pprint.pprint(data[0][1])
break
imap.close()
and I'm getting the following error for everything I have tried.
993
Connected to server.
b'* OK [CAPABILITY IMAP4rev1 CHILDREN ENABLE ID IDLE LIST-EXTENDED LIST-STATUS LITERAL- MOVE NAMESPACE SASL-IR SORT SPECIAL-USE THREAD=ORDEREDSUBJECT UIDPLUS UNSELECT WITHIN AUTH=LOGIN AUTH=PLAIN] IMAP server ready H migmxus021 26.3 IMAP-1MDPaK-1ole8h3s9u-00AOkg'
Traceback (most recent call last):
File "/home/rehman/twitterBots/twitter_center/test.py", line 26, in <module>
imap.login(imap_user, imap_pass)
File "/home/rehman/anaconda3/envs/bots/lib/python3.9/imaplib.py", line 593, in login
raise self.error(dat[-1])
imaplib.IMAP4.error: b'authentication failed'
Please NOTE: I'm able to log in using the email and password perfectly fine using the web browser. They are correct.
I'm not sure what's wrong here but I have tried everything for days, multiple emails, etc. Help would be appreciated.
Try to generate an App Password on your Yahoo account, then test to see if at least the yahoo works.