in reply to gmail pop3 authentication

My problem is with the authentication.

I think your problem is you're not using some email module, like Mail::IMAPClient

email is complicated, there are a lot of details -- sure they're all public details , but why reinvent the wheel