Как я могу отправить электронную почту на несколько адресов в моем коде Python?
#!/usr/bin/python
import smtplib
import sys, getopt
recipient=''
subject=''
body=''
try:
myopts, args = getopt.getopt(sys.argv[1:],"r:s:m:")
except getopt.GetoptError as e:
print (str(e))
print("Usage: %s -r recipient -s subject -m message" % sys.argv[0])
sys.exit(2)
for o, a in myopts:
if o == '-r':
recipient=a
elif o == '-s':
subject=a
elif o == '-m':
body=a
server = 'smtp.gmail.com'
port = 587
sender = 'foo@bar'
password = 'password'
headers = ["From: " + sender,
"Subject: " + subject,
"To: " + recipient,
"MIME-Version: 1.0",
"Content-Type: text/html"]
headers = "\r\n".join(headers)
session = smtplib.SMTP(server, port)
session.ehlo()
session.starttls()
session.ehlo
session.login(sender, password)
session.sendmail(sender, recipient, headers + "\r\n\r\n" + body)
session.quit()