Clean mailbox
Tags: #gmail #productivity #naas_drivers #operations #automation #scheduler
Description: This notebook helps you quickly and easily organize your Gmail inbox by removing unwanted emails.
import naas
from naas_drivers import email
import pandas as pd
import numpy as np
import plotly.express as px
username
: This variable stores the username or email address associated with the email accountpassword
: This variable stores the password or authentication token required to access the email accountsmtp_server
: This variable represents the SMTP server address used for sending emails.box
: This variable stores the name or identifier of the mailbox or folder within the email account that will be accessed.remove_emails_from
: This variable stores the list of emails to be deleted in your email box
# Inputs
username = "[email protected]"
password = naas.secret.get("GMAIL_APP_PASSWORD") or "xxxxxxxx"
smtp_server = "imap.gmail.com"
box = "INBOX"
remove_emails_from = ["[email protected]"]
# Outputs
cron = "0 20 * * *" #everyday at 8PM
emails = email.connect(username, password, smtp_server=smtp_server)
df_emails = emails.get()
print(f"✅ Emails fetched:", len(df_emails))
df_emails.head(1)
for index, df in enumerate(df_emails["from"]):
sender_email = df["email"]
uid = df_emails.loc[index, "uid"]
subject = df_emails.loc[index, "subject"]
if sender_email in remove_emails_from:
emails.set_flag(uid, "DELETED")
print(f"✅ Email '{subject}' from '{sender_email}' removed from mailbox.")
naas.scheduler.add(cron=cron)
Last modified 28d ago