Python Program For Email Header Analyzer

Want to know how to create python program for email header analyzer, then you are at the right place today in this tutorial. I will show you how to create a python program for email header analyzer, so follow this tutorial till the end.
To create this program we will use the imaplib and email library which comes preinstalled with python. This program will analyze all your emails and print the header details of your emails.
Email Header Analyzer In Python Code
import imaplib
import email
imap_server = "imap.gmail.com"
# Enter your email here
email_address = "[email protected]"
# Enter your email password
password = "test password"
imap = imaplib.IMAP4_SSL(imap_server)
imap.login(email_address,password)
imap.select("Inbox")
_, messageNums = imap.search(None,"ALL")
for messageNum in messageNums[0].split():
_, data = imap.fetch(messageNum,"(RFC822)")
message = email.message_from_bytes(data[0][1])
print(f"Message number: {messageNum}")
print(f"From: {message.get('From')}")
print(f"To: {message.get('To')}")
print(f"BCC: {message.get('BCC')}")
print(f"Date: {message.get('Date')}")
print(f"Subject: {message.get('Subject')}")
print("Content: ")
for part in message.walk():
if part.get_content_type() == "text/plain":
print(part.as_string())
imap.close()
Above is the python program for email header analyzer. Now to run this program you need to have python installed on your computer, If you don’t have then follow this guide: Install and setup python on your computer.
To run this python program, follow the below steps:
- Create a new folder for this python project.
- Open it in a code editor of your choice.
- Create a python file with an ending .py extension.
- Copy the above code and paste it in your file.
- Open a terminal or CMD at folder location
- And type this command python filename.py (Name of your file).
After running this program you will see your email header details printed in the console window.
Summary
This was a simple python program for email head analyzer I hope you found this tutorial helpful and useful. Do share this tutorial with your friends who might be interested in this program.
Here are some more python program tutorials for you:
- Python Program To Convert MegaBytes To Bytes.
- Python Program To Convert Miles To Feet.
- Python Program To Convert Rupee To Paise.
I hope you found what you were looking for from this tutorial, and if you want more python programs and tutorials like this, do join our Telegram channel for future updates.
Thanks for reading, have a nice day 🙂