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 4054802
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:37:18+00:00 2026-05-20T14:37:18+00:00

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’,

  • 0
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', 'password')
print rc, resp

M.select()
for msg_num in M.search(None, "UNDELETED")[1][0].split():
    msg = M.fetch('1', '(BODY.PEEK[TEXT])') 
    print msg[1][0][1][139:161]

M.close()         
M.logout()

I’m a new beginner in python programming and the above python code is one that I’m using for a program I want to do. When I run this in a terminal I get the response that I have authenticated my account and then it displays the message between characters 139 & 161, which is the following in the example email:

This is just a test…

This is printed out in the terminal. What I want to do is take this printout and compare it to something else. For example: if a=b then x. What I want to do is that if the statement is true to send a signal to the serial port.

Any help is appreciated and anticipated thanks to all that help…

  • 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-20T14:37:18+00:00Added an answer on May 20, 2026 at 2:37 pm

    Simply assign the message to a variable before you print it:

    for msg_num in M.search(None, "UNDELETED")[1][0].split():
        msg = M.fetch('1', '(BODY.PEEK[TEXT])') 
        a = msg[1][0][1][139:161]
        print a
    
    # later..
    if a == 'this is just a test...':
       # your code here
       pass
    

    Obviously, you should use a more meaningful variable name than “a“.

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

Sidebar

Related Questions

import imaplib usr = 'someuser' pwd = 'somepwd' imap_server = imaplib.IMAP4_SSL('imap.gmail.com', 993) imap_server.login(USER, PASSWORD)
import serial import imaplib from time import sleep IMAP_SERVER='imap.gmail.com' IMAP_PORT=993 ser= serial.Serial ('/dev/ttyACM0',9600) M
import serial import imaplib from time import sleep IMAP_SERVER='imap.gmail.com' IMAP_PORT=993 ser= serial.Serial ('/dev/ttyACM0',9600) while
This script: import imaplib user = dave.trindall@gmail.com pwd = *** m = imaplib.IMAP4_SSL(imap.gmail.com) m.login(user,pwd)
import imaplib M=imaplib.IMAP4_SSL('imap.gmail.com', 993) when run on my pc it works and alls fine,
I have the following code: import imaplib import email import codecs mail = imaplib.IMAP4_SSL('imap.gmail.com')
Here is the code I have thus far: import email, imaplib user = 'some
I am using imaplib to read gmail messages in my python command window. The
how do i read mails from my mail box using python?? import getpass, imaplib
import com.mockobjects.sql.*; The above line creates the error The import com.mockobjects.sql cannot be resolved

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.