I need to send an email to 100 recipients. When I send message to one recipient, it takes three seconds. And when I send it to three recipients at once, it also takes three seconds.
So I use multiple recipient to send the message faster.
def send(x, y, z):
to = [x, y, z]
subject="Multi Test"
gmail_user = 'test@gmail.com'
gmail_pwd = 'test'
smtpserver = smtplib.SMTP("smtp.gmail.com", 587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_pwd)
header = 'To:' + ", ".join(to) + '\n' + 'From: ' + gmail_user + '\n' + 'Subject: ' + subject + '\n'
msg = header + '\n' + subject + '\n\n'
smtpserver.sendmail(gmail_user, to, msg)
smtpserver.close()
the email that i want to send message for is
1@yahoo.com, 2@yahoo.com, 3@yahoo.com....., 100@yahoo.com
so i want the script split into threes emails then send the message
or if you know another way to create script to send the message faster
Change your function to
def send(to):
// ..
header = 'To:' + ", ".join(to)
Then call it as
send(["1@yahoo.com", "2@yahoo.com", "3@yahoo.com", ..., "100@yahoo.com"])
But think about the following:
email.message
to build an email. Don't just concat strings.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.