import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from datetime import datetime import time # AWS SES SMTP settings aws_smtp_server = "email-smtp.ap-south-1.amazonaws.com" aws_smtp_port = 587 aws_smtp_username = "YOUR_SES_SMTP_USERNAME" aws_smtp_password = "YOUR_SES_SMTP_PASSWORD" sender_email = "Customer Helpdesk " # Email subject and body subject = "Reminder to Complete Registration" body = """

Dear Candidate,

This is a reminder to complete your online registration. Please complete all required steps before the registration closing date.

This is an auto-generated email. Please do not reply to this message.

Regards,
Customer Helpdesk

""" # Output log output_file = "email_send_status.txt" # Batch settings batch_size = 1500 pause_seconds = 60 def send_email(to_email): msg = MIMEMultipart() msg["From"] = sender_email msg["To"] = to_email msg["Subject"] = subject msg.attach(MIMEText(body, "html")) with smtplib.SMTP( aws_smtp_server, aws_smtp_port ) as server: server.starttls() server.login( aws_smtp_username, aws_smtp_password ) server.send_message(msg) # Read email list with open("list_of_emails.txt", "r") as file: all_emails = [ email.strip() for email in file if email.strip() ] total_emails = len(all_emails) print(f"Total emails to send: {total_emails}") # Send emails in batches with open(output_file, "a") as output: for i in range(0, total_emails, batch_size): batch = all_emails[i:i + batch_size] batch_number = i // batch_size + 1 print( f"\n--- Sending batch {batch_number} " f"({len(batch)} emails) ---" ) for email in batch: try: send_email(email) status = ( f"{datetime.now():%Y-%m-%d %H:%M:%S} - " f"Email sent successfully to {email}" ) print(status) output.write(status + "\n") except Exception as e: status = ( f"{datetime.now():%Y-%m-%d %H:%M:%S} - " f"Failed to send email to {email}: {e}" ) print(status) output.write(status + "\n") # Save log after each batch output.flush() # Wait before the next batch if i + batch_size < total_emails: print( f"Waiting {pause_seconds} seconds " f"before next batch..." ) time.sleep(pause_seconds) print("\nAll emails processed.") print(f"Check {output_file} for details.")