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()