VOOZH about

URL: https://www.geeksforgeeks.org/python/fetch-unseen-emails-from-gmail-inbox/

⇱ Fetch Unseen Emails From Gmail Inbox - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Fetch Unseen Emails From Gmail Inbox

Last Updated : 15 Jul, 2025

Python is a widely used high-level, general-purpose, interpreted, multi-utility, dynamic programming language. It can be used to do a wide range of tasks like machine learning, web application development, cross-platform GUI development, and much more. Fetching Gmail is another of a task that could be achieved by Python. You may need to fetch a mail from your inbox in your project or website for any reason. In this tutorial, we'll learn about how to fetch unseen emails from Gmail Inbox/Sent Mails.
To begin, we will be required an app password that is generated by Google Security, since using Password cannot be secure using in some projects or scripts directly.


How to Generate App Password :

  1. Go to account.google.com with your account.
  2. In left tabs, choose Security.
  3. Under Signing into Google, Choose App Password.
  4. Confirm your identity.
  5. Choose Custom.
  6. Choose any name for your Application and Generate the Password.
  7. That's your App Password. Copy the password, we'll be needing that.


You'll also need to Enable IMAP in the Google Settings. 

👁 enable IMAP in gmail


The Library you'll use are : 
 

  1. imaplib
  2. email
  3. webbrowser
  4. os


That's all for the prerequisite. Let's see the code now.
 

Output: This code will fetch you the top 20 unseen emails in the inbox.

👁 gmail draft unseen message


 

👁 gmail draft unseen message-2


 

👁 gmail draft unseen message-3

Comment