I have written the following code to send an email that simply sends "test" to a specified email address.
import smtplib
sentFrom = "my email"
to = input("Enter email: ")
#numberEmails = raw_input ("Enter number of emails to send")
messageText = "test"
msg = "From: %s\n To: %s\n\n%s" % (sentFrom, to, messageText)
username = str("my email")
password = str("my password")
try :
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(username,password)
server.sendmail(sentFrom, to, msg)
server.quit()
print (" Email has sent")
except :
print("email NOT sent")
When I try to send more emails than 1, for example:
5*server.sendmail(sentFrom, to, msg)
Only one email sends, then I get the error "email NOT sent." I do not get an "email has sent" after the first email sends, only an "email NOT sent" print after the first. How can I fix this issue? I want to eventually have an input() so I can enter in the number of emails to send, and the program sends the number of emails entered into the input. I put how I think this would look as a comment at the top. Can I just multiply the server.sendmail command by the numberEmails command?
This is my first day using Python so go easy on me pls. :)