-1

I am trying to fetch mail from a email account, I cannot login when I have password with special characters.

import imaplib
username = 'test@test.com'
password = "test!002"
imap_server = 'imap.test.com'
mail = imaplib.IMAP4_SSL(imap_server)
mail.login(username, password)

Output:

[AUTHENTICATIONFAILED] Invalid credentials(Failure)' Exception in connectionb'[AUTHENTICATIONFAILED] Invalid credentials(Failure)

The same code works if I change the password which does not special Characters. Can any one tell me how to login to imap with passwords containing special characters.

Gaurav Modi
  • 82
  • 1
  • 10

1 Answers1

0

I'm not sure if this will help you but i have looked at the documentation and found this.

IMAP4.authenticate changed in version 3.5: string usernames and passwords are now encoded to utf-8 instead of being limited to ASCII.

You could try to encode the password, maybe the username also just in case, and retry it?

For more information please read:

IMAP4.authenticate(mechanism, authobject)

Scircia
  • 419
  • 3
  • 10