for i in range(3):
gmail_user = 'email'
gmail_password = 'pass'
sent_from = gmail_user
to = ['email']
subject = 'Lorem ipsum dolor sit amet'
body = rand_quote
email_text = ("""\
From: %s
To: %s
Subject: %s
%s
""" % (sent_from, ", ".join(to), subject, body))
try:
smtp_server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
smtp_server.ehlo()
smtp_server.login(gmail_user, gmail_password)
smtp_server.sendmail(sent_from, to, email_text)
smtp_server.close()
print ("Email sent successfully!")
except Exception as ex:
print ("Something went wrong….",ex)
When I remove the for loop the code runs great with the subject and body sending properly however when I try to run something like the code above the email comes is sent as such.