Jump to content

Recommended Posts

Posted

Hi!
I'm trying to run this python code on tommy:

 

import imaplib
import email

 

mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('myaccount@gmail.com', 'mypwd')
x,y=mail.status('INBOX','(MESSAGES UNSEEN)')
messages=int(re.search('MESSAGES\s+(\d+)',y[0]).group(1))
unseen=int(re.search('UNSEEN\s+(\d+)',y[0]).group(1))
print messages
print unseen 

 

It doesn't execute it because it doen't print anything. Can you help me?
Simpler codes with only a print execute well

 

Posted

Gmail is a known issue, and it's to do with Google's security. It doesn't like being accessed because of its security requirements. You need to do a few things...

 

First, make sure you go in your Google settings and turn on the "Allow less secure applications to access your account" option. With this setting turned off, the only apps that work are the gmail website and cell phones. Even Microsoft Outlook requires that setting be turned on...

 

After that, you need to write your Python to use SSL for IMAP and access their server on port 993. I don't know how to do this step in Python, so you'll need to refer to the documentation for that.

Posted

Thank you very much! I found out that my code works with another email address so it's sure that the problem depended on Google. I'll try with my gmail address following your tips.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...