Mass python email sender
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def read_emails_from_file(file_path):
with open(file_path, 'r') as file:
emails = [line.strip() for line in file.readlines()]
return emails
def send_email(subject, body, to_email, smtp_server, smtp_port, sender_email, sender_password):
message = MIMEMultipart()
message['From'] = sender_email
message['To'] = ', '.join(to_email)
message['Subject'] = subject
message.attach(MIMEText(body, 'plain'))
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(sender_email, sender_password)
server.sendmail(sender_email, to_email, message.as_string())
# User inputs
subject = input("Enter the email subject: ")
body = input("Enter the email body: ")
file_path = input("Enter the path to the file with email addresses: ")
smtp_server = input("Enter the SMTP server: ")
smtp_port = int(input("Enter the SMTP port: "))
sender_email = input("Enter your email address: ")
sender_password = input("Enter your email password: ")
# Reading email addresses from the file
to_email_list = read_emails_from_file(file_path)
# Sending email to each recipient in the list
for recipient_email in to_email_list:
send_email(subject, body, [recipient_email], smtp_server, smtp_port, sender_email, sender_password)