Skip to content

aviskarrr/bulkmail-smtp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Bulk Email Sender with Attachments (Python)

This Python script allows you to send personalized emails with attachments in bulk using data from an Excel file. Each recipient gets a customized message and file attachment.

It’s suitable for workshops, events, certificates, reports, or general mailings.


1. Prerequisites

Before running the script, make sure you have:

  • Python 3 installed

  • Python libraries: pandas, smtplib, email, pathlib Install pandas if needed:

    pip install pandas
  • A Gmail account with 2-Step Verification enabled (needed for App Passwords)


2. Setting up Gmail App Password

  1. Open your Google Account: https://myaccount.google.com

  2. Go to Security2-Step Verification and enable it.

  3. Under Security, click App passwords.

  4. Select:

    • App → Mail
    • Device → Other (e.g., “Python script”)
  5. Click Generate and copy the 16-character App Password.

  6. Use this App Password in your script instead of your normal Gmail password.


3. SMTP and Port

  • SMTP is the protocol used to send emails programmatically.

  • For Gmail:

    • SMTP server: smtp.gmail.com
    • TLS port: 587
  • TLS encrypts your email during sending to ensure security.


4. Excel File Setup

The script reads an Excel file with recipient data. Your Excel file should have the following columns:

Column Name Description Example
Name Recipient’s name John Doe
Mail Recipient’s email address john@example.com
Path Full path to the file you want to attach C:\Users\John\Documents\report.pdf
  • Column names must match exactly (case-sensitive).
  • Path should include the full filename and extension.
  • Example Excel file: recipients.xlsx

5. Configuring the Script

Open the Python script and replace placeholders:

  1. Excel file path

    excel_file_path = 'recipients.xlsx'  # path to your Excel file
  2. Sender email and App Password

    sender_email = 'YOUR_EMAIL_HERE'
    sender_password = 'YOUR_APP_PASSWORD_HERE'
  3. SMTP server and port

    smtp_server = 'smtp.gmail.com'
    smtp_port = 587
  4. Email subject and body

    • Customize msg['Subject'] and body.
    • The script automatically includes each recipient’s name.

6. How the Script Works

  1. Reads the Excel file and iterates over all rows.
  2. Checks that the attachment file exists.
  3. Creates a personalized email for each recipient.
  4. Attaches the file.
  5. Sends the email via Gmail SMTP.
  6. Prints logs for sent or skipped emails.
  7. Closes the SMTP connection after sending all emails.

7. Safety Tips

  • Always test with 1-2 emails before sending to everyone.
  • Make sure all attachment files exist at the specified paths.
  • Avoid sending too many emails at once; Gmail may block or limit your account.
  • Never share your real Gmail password; use an App Password.

8. Optional Improvements

  • Add a delay between sending emails to avoid Gmail rate limits:

    import time
    time.sleep(2)  # 2-second delay between emails
  • Use HTML emails for better formatting.

  • Log sent or failed emails to a CSV for tracking.

  • Make the script reusable for multiple types of emails by adding a column like “Category” in Excel.

About

A Python script to send personalized emails with attachments in bulk using Excel. Designed for general-purpose use, this tool allows users to automate email delivery via SMTP with Gmail App Passwords, making it suitable for certificates, reports, newsletters, or any type of bulk mailing.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages