robocorp / rpaframework

Collection of open-source libraries and tools for Robotic Process Automation (RPA), designed to be used with both Robot Framework and Python
https://www.rpaframework.org/
Apache License 2.0
1.17k stars 227 forks source link

RPA.Email.ImapSmtp: Lookup Error while trying to use list_messages. #460

Closed kskolte2020 closed 1 year ago

kskolte2020 commented 2 years ago

Python Version: 3.8.3 rpaframework = 13.1.0

I found error while I was trying to download attachments from mails using RPA.Email.ImapSmtp in Python. Actually, updated the framework to latest version then I was getting error as LookupError: unknown encoding: None. Then I downgraded to v13.0.1 tracking the changes made, however I still got same error. Then finally I downgraded to v12.8.2 and that worked. So I guess there's error in v12.9.0 or in between 12.9.0 - 13.0.1

mikahanninen commented 2 years ago

Can you post example code you were trying to use ?

kskolte2020 commented 2 years ago
mail = ImapSmtp(smtp_server="smtp.gmail.com", smtp_port=587)
mail.authorize(account=__gmail_account, password=__gmail_password)
if not inbox_folder:
    mails = mail.list_messages(mail_criteria, source_folder='GmailFolderName')
    print(mails)
else:
    mails = mail.list_messages(mail_criteria, source_folder='Inbox')

I tried to print mails variable, but bcz of error it was getting into exception block.

mikahanninen commented 2 years ago

And your mail_criteria is some sort of string ?

mikahanninen commented 2 years ago

And what is the specific Python version you are using ? Python version should be determined by x.yz version number like 3.8.7 and not just 3.8 .

kskolte2020 commented 2 years ago

And your mail_criteria is some sort of string ?

Yes, it's a string.

kskolte2020 commented 2 years ago

And what is the specific Python version you are using ? Python version should be determined by x.yz version number like 3.8.7 and not just 3.8 .

My apologies, it's 3.8.3

mikahanninen commented 2 years ago

I run your example with rpaframework versions 13.0.0 and 13.2.0 without problems.

from RPA.Email.ImapSmtp import ImapSmtp
from RPA.Robocorp.Vault import Vault

def list_emails(mail_criteria, inbox_folder=True):
    secrets = Vault().get_secret("gmailtest")
    mail = ImapSmtp(smtp_server="smtp.gmail.com", smtp_port=587)
    mail.authorize(account=secrets["username"], password=secrets["password"])
    if not inbox_folder:
        mails = mail.list_messages(mail_criteria, source_folder="custom name")
        print(mails)
    else:
        mails = mail.list_messages(mail_criteria, source_folder="INBOX")
        print(mails)

def minimal_task():
    list_emails('SUBJECT "New Test Email from Friday 25/MAR/22"')
    print("Done.")

if __name__ == "__main__":
    minimal_task()
kskolte2020 commented 2 years ago

I run your example with rpaframework versions 13.0.0 and 13.2.0 without problems.

from RPA.Email.ImapSmtp import ImapSmtp
from RPA.Robocorp.Vault import Vault

def list_emails(mail_criteria, inbox_folder=True):
    secrets = Vault().get_secret("gmailtest")
    mail = ImapSmtp(smtp_server="smtp.gmail.com", smtp_port=587)
    mail.authorize(account=secrets["username"], password=secrets["password"])
    if not inbox_folder:
        mails = mail.list_messages(mail_criteria, source_folder="custom name")
        print(mails)
    else:
        mails = mail.list_messages(mail_criteria, source_folder="INBOX")
        print(mails)

def minimal_task():
    list_emails('SUBJECT "New Test Email from Friday 25/MAR/22"')
    print("Done.")

if __name__ == "__main__":
    minimal_task()

It happened for me in few set of mail criteria, not all, however after downgrade that worked without errors

mikahanninen commented 2 years ago

What kind of criteria do you mean?

kskolte2020 commented 2 years ago

What kind of criteria do you mean?

I got error in this two example criteria: 'Subject "Invoice" Subject "My Company" Unseen' and 'Subject "Invoice" Subject "My Industries & Co" Unseen'

tonnitommi commented 1 year ago

Please re-open if the issue still exists.