Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7497477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:07:04+00:00 2026-05-29T19:07:04+00:00

import imaplib usr = ‘someuser’ pwd = ‘somepwd’ imap_server = imaplib.IMAP4_SSL(‘imap.gmail.com’, 993) imap_server.login(USER, PASSWORD)

  • 0
import imaplib

usr = 'someuser'
pwd = 'somepwd'

imap_server = imaplib.IMAP4_SSL('imap.gmail.com', 993)
imap_server.login(USER, PASSWORD)
imap_server.select('Inbox')

for message_id in imap_server.search(None, '(FROM "example email.com")')[1][0].split(" "):
    response = imap_server.fetch(message_id, "RFC822.TEXT")
    print response[1][0][1]

I want to search for email with a certain subject and from email address. How do I adjust this code to fit incorporate both check?

Also, once i open a message, I want to search the message for certain content. What
is the best way to go about this? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:07:06+00:00Added an answer on May 29, 2026 at 7:07 pm

    The python imap wrapper is very thin – it simply exposes the imap specification, see http://www.faqs.org/rfcs/rfc3501.html

    in the fetch command you can fetch several parts of the mail, you choose to fetch the entire RFC formated mail. You can also search like this:

    typ, data = imap_server.search(None, '(SUBJECT "Whatever you are searching for")')
    

    You already showed how to fetch a mail. When you have the RFC-mail in your hands. Search in this mail, depends on what your criteria is: a regex, something in the headers, …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import imaplib import pprint IMAP_SERVER='imap.gmail.com' IMAP_PORT=993 M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT) rc, resp = M.login('user@gmail.com',
This script: import imaplib user = dave.trindall@gmail.com pwd = *** m = imaplib.IMAP4_SSL(imap.gmail.com) m.login(user,pwd)
import serial import imaplib from time import sleep IMAP_SERVER='imap.gmail.com' IMAP_PORT=993 ser= serial.Serial ('/dev/ttyACM0',9600) while
import serial import imaplib from time import sleep IMAP_SERVER='imap.gmail.com' IMAP_PORT=993 ser= serial.Serial ('/dev/ttyACM0',9600) M
import imaplib M=imaplib.IMAP4_SSL('imap.gmail.com', 993) when run on my pc it works and alls fine,
Here is the code I have thus far: import email, imaplib user = 'some
how do i read mails from my mail box using python?? import getpass, imaplib
I just ran into an issue with Python's imaplib and Gmail's authentication mechanism: >>>
I am using imaplib to read gmail messages in my python command window. The
I'm using pythons imaplib to connect to my gmail account. I want to retrieve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.