0% found this document useful (0 votes)
6 views5 pages

Sagar Dhake's Spam Email Detector

The document outlines a project titled 'Spam Email Detector' created by Sagar Pralhad Dhake, a student in the FYMCA program. It includes a Python script that utilizes IMAP to fetch emails from a Gmail account and identifies spam based on predefined keywords. The script features a graphical user interface for user input and displays whether each fetched email is classified as 'SPAM' or 'HAM'.

Uploaded by

sagar dhake
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Sagar Dhake's Spam Email Detector

The document outlines a project titled 'Spam Email Detector' created by Sagar Pralhad Dhake, a student in the FYMCA program. It includes a Python script that utilizes IMAP to fetch emails from a Gmail account and identifies spam based on predefined keywords. The script features a graphical user interface for user input and displays whether each fetched email is classified as 'SPAM' or 'HAM'.

Uploaded by

sagar dhake
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NAME : SAGAR PRALHAD DHAKE

ROLL NO: 24
TITLE : SPAM EMAIL DETECTOR
BATCH : B2
CLASS : FYMCA
import imaplib, email
from [Link] import decode_header
import tkinter as tk
from tkinter import simpledialog, messagebox

keywords = ["free money", "winner", "congratulations", "urgent", "credit card", "click


here", "lottery", "act now", "limited offer", "100% free", "guaranteed", "investment", "no
cost", "extra cash", "apply now", "cash bonus", "fast cash", "cheap meds", "meet
singles", "risk-free", "earn per week", "work from home", "get paid", "miracle", "exclusive
deal", "urgent response", "pre-approved", "access now", "trial offer", "join my class",
"let's have fun", "interview"]

def is_spam(text): return any(k in [Link]() for k in keywords)

def fetch_emails(user, pwd, limit):


try:
imap = imaplib.IMAP4_SSL("[Link]"); [Link](user, pwd);
[Link]("inbox")
_, msgs = [Link](None, "ALL"); ids = msgs[0].split()[-limit:]
for i in ids:
_, data = [Link](i, "(RFC822)")
msg = email.message_from_bytes(data[0][1])
subj = "".join([[Link](enc or "utf-8") if isinstance(p, bytes) else p for p, enc in
decode_header(msg["subject"] or "")])
body = ""
for part in [Link]():
if part.get_content_type() == "text/plain" and not [Link]('Content-
Disposition'):
body = part.get_payload(decode=True).decode(errors="ignore"); break
result = "SPAM" if is_spam(subj + " " + body) else "HAM"
print(f"[{result}] {[Link]('date')} | {subj}\n{body[:60].strip()}...\n" + "-"*60)
[Link]()
except Exception as e: [Link]("Error", str(e))

def gui():
r = [Link](); [Link]()
u = [Link]("Email", "Gmail:"); p = [Link]("Password",
"App Password:", show="*")
l = [Link]("Limit", "How many emails?", minvalue=1)
if u and p and l: fetch_emails(u, p, l)

gui()
OUTPUT:-
Enter email:-

Enter password:-
Enter limit of email:-

You might also like