Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views1 page

Code

The document is a Python script that reads email addresses and SMTP server information from text files. It sends emails in a loop using a cycling mechanism for the SMTP servers. The script includes functions for reading files and sending emails with error handling.

Uploaded by

cloki7920
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Code

The document is a Python script that reads email addresses and SMTP server information from text files. It sends emails in a loop using a cycling mechanism for the SMTP servers. The script includes functions for reading files and sending emails with error handling.

Uploaded by

cloki7920
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import smtplib

from itertools import cycle

def read_file(file_path):
with open(file_path, 'r') as file:
return [line.strip() for line in file]

def send_email(smtp_info, sender, recipient, subject, body):


try:
server = smtplib.SMTP(smtp_info['host'], smtp_info['port'])
server.starttls()
server.login(smtp_info['username'], smtp_info['password'])
message = f"From: {sender}\nTo: {recipient}\nSubject: {subject}\n\n{body}"
server.sendmail(sender, recipient, message)
server.quit()
print(f"Email sent to {recipient} using {smtp_info['host']}")
except Exception as e:
print(f"Failed to send email to {recipient}: {e}")

def main():
emails = read_file('data.txt')
smtp_servers = read_file('smtp.txt')
smtp_info_list = [{'host': smtp.split()[0], 'port': int(smtp.split()[1]),
'username': smtp.split()[2], 'password': smtp.split()[3]} for smtp in smtp_servers]

smtp_cycle = cycle(smtp_info_list)

sender = '[email protected]'
subject = 'Your Subject Here'
body = 'Your Email Body Here'

for email in emails:


smtp_info = next(smtp_cycle)
send_email(smtp_info, sender, email, subject, body)

if __name__ == "__main__":
main()

You might also like