Skip to main content

Mail List

 

import csv
import smtplib
from email.mime.text import MIMEText
 
# Define the email parameters
sender_email = 'your_email@example.com'
sender_password = 'your_email_password'
subject = 'Update your password'
message_template = '''\
Dear {name},
 
Please update your password for our service. You can do this by logging into your account and changing your password.
 
Thank you,
The Service Team
'''
 
# Read the CSV file and send an email to each user
with open('user_data.csv') as file:
      reader = csv.reader(file)
      next(reader)  # Skip header row
      for row in reader:
          # Extract user data
          name, email = row
          # Create the email message
          message = message_template.format(name=name)
          email_message = MIMEText(message)
          email_message['Subject'] = subject
          email_message['From'] = sender_email
          email_message['To'] = email
          # Connect to the SMTP server and send the email
          with smtplib.SMTP('smtp.gmail.com', 587) as server:
              server.starttls()
              server.login(sender_email, sender_password)
              server.sendmail(sender_email, email, email_message.as_string())
          print(f'Sent email to {name} ({email})')