Jump to content

Problem with email python


mattia95

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...