Categories We Write About

Create an email delay tracker

Creating an email delay tracker involves monitoring the time it takes for emails to be sent, delivered, or responded to. Depending on the environment, this can be implemented with different approaches—ranging from simple scripts to integrated tracking in email platforms.

Here’s a straightforward way to create an email delay tracker using Python that logs the time an email is sent and later checks for a response or delivery confirmation. This example assumes you’re using SMTP for sending emails and IMAP for checking replies.


Email Delay Tracker (Python Script)

python
import smtplib import imaplib import email import time from datetime import datetime # Configuration SMTP_SERVER = 'smtp.example.com' SMTP_PORT = 587 IMAP_SERVER = 'imap.example.com' EMAIL_ACCOUNT = 'your_email@example.com' EMAIL_PASSWORD = 'your_password' # Tracking dictionary sent_emails = {} def send_email(to_address, subject, body): global sent_emails # Connect to SMTP server and send email with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server: server.starttls() server.login(EMAIL_ACCOUNT, EMAIL_PASSWORD) message = f"Subject: {subject}nn{body}" server.sendmail(EMAIL_ACCOUNT, to_address, message) # Log the sent email with timestamp sent_emails[to_address] = datetime.now() print(f"Email sent to {to_address} at {sent_emails[to_address]}") def check_replies(): # Connect to IMAP server and check inbox for replies mail = imaplib.IMAP4_SSL(IMAP_SERVER) mail.login(EMAIL_ACCOUNT, EMAIL_PASSWORD) mail.select('inbox') # Search all emails in inbox result, data = mail.search(None, 'ALL') mail_ids = data[0].split() for mail_id in mail_ids: result, msg_data = mail.fetch(mail_id, '(RFC822)') raw_email = msg_data[0][1] msg = email.message_from_bytes(raw_email) from_email = email.utils.parseaddr(msg['From'])[1] subject = msg['Subject'] date_str = msg['Date'] msg_date = datetime.strptime(date_str[:25], '%a, %d %b %Y %H:%M:%S') # Check if this email is a reply to a tracked email if from_email in sent_emails: sent_time = sent_emails[from_email] delay = msg_date - sent_time print(f"Reply from {from_email} received. Delay: {delay}") # Remove from tracking after reply received del sent_emails[from_email] mail.logout() # Example usage send_email('recipient@example.com', 'Test Email', 'This is a test email.') time.sleep(10) # Wait before checking replies, typically longer in real use check_replies()

Explanation:

  • send_email() sends an email and logs the sending time.

  • check_replies() connects to the inbox and looks for replies from the recipients of the tracked emails.

  • It calculates the delay between sending and receiving a reply.

  • The script assumes replies come from the same email address the original mail was sent to.


Notes for practical use:

  • For large-scale or commercial usage, consider integrating with email APIs like Gmail API, Microsoft Graph, or services like SendGrid.

  • Adding message IDs and threading headers can improve reply tracking accuracy.

  • You may want to store sent email timestamps in a database or persistent storage.

  • Extend with notifications or dashboards for monitoring delays visually.

If you want, I can also help create a version tailored for a specific email service or with more detailed features.

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About