Package: email-monitor
Email MonitorEmail Monitor is a Python module designed for monitoring and searching emails using the IMAP protocol. It is particularly useful for tasks such as OTP code scraping for web automation, email parsing, and email notifications.This module is primarily focused on Gmail using OAuth2 for authentication, but it can also work with other IMAP email providers. It is currently in beta, so please report any bugs or issues you encounter, I would greatly appreciate it!InstallationYou can install the Email Monitor module using pip:pipinstallemail-monitorWhat is this module?The Email Monitor module is a Python library that enables you to efficiently search, parse, and monitor emails in your mailbox. By providing an intuitive interface for email handling, this module simplifies the process of obtaining specific information from your emails, such as OTP codes, notifications, or important updates.Use CasesSome of the key use cases for this module include:Automatically retrieving OTP codessent to your email for web automation tasksParsing email contentto extract relevant data or notificationsMonitoring your mailbox for specific emails, such as those containing a particular subject, sender, or contentSupported IMAP ProvidersEmail Monitor is primarily designed to work with Gmail using OAuth2 authentication, but it can also support other IMAP email providers. To set up Gmail OAuth2 authentication, follow these steps:Go to theGoogle Cloud ConsoleCreate a new project or select an existing oneNavigate to "APIs & Services" > "Library" and enable the "Gmail API"Navigate to "APIs & Services" > "Credentials" and create a new "OAuth 2.0 Client ID"Download thecredentials.jsonfile for your newly created OAuth 2.0 clientExampleHere's a quick example of how to use the Email Monitor module:fromemail_monitorimportEmailMonitorimportremonitor=EmailMonitor(credentials_file="credentials.json")email=monitor.search_mail(query={"subject":"Your OTP Code","from":"noreply@example.com","text":re.compile("OTP: \d{6}")},wait_for_match=True,unread=True,labels=["INBOX"],delay=10)print(email)Take a look at theexamplesfolder for more examples of how to use this module.Search Mail ParametersThesearch_mailfunction has several parameters that can be used to customize your search:query(dict): A dictionary containing the search query. The keys are the search parameters and the values are the search terms. Regex is supported.
Example:{"subject": "Hello", "from": "John Doe", "to": "myOtherMail@gmail.com", "text": re.compile("Hello World")}wait_for_match(bool): If set to True, the function will wait for a new email to match the query and return it.unread(bool): If set to True, the function will search for emails that have already been read.labels(list): A list of labels to search for. Only works with Gmail.delay(int): The delay in seconds between each search ifwait_for_matchis set to True.ContributingContributions are welcome! Feel free to submit pull requests with bug fixes or new features. Check out thecontributing guidelinesfor more information.LicenseThis project is licensed under the MIT License - see theLICENSEfile for details.Contact MeIf you have any questions or suggestions, feel free to reach out to me:GitHub:glizzykingdrekoMedium:glizzykingdrekoTwitter:glizzykingdrekoEmail:glizzykingdreko@protonmail.com