0
import sys
import datetime

me = sys.argv[1]
you = sys.argv[2]  #[I want to pass here multiple recipient]
subject = datetime.now().strftime("%I %P")

# Create the root message and fill in the from, to, and subject headers
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = 'Status Update ' + str(subject)
msgRoot['From'] = me
msgRoot['To'] = you
#msgRoot['To'] = ",".join(you) 
"""Earlier I was using something like above when I was hardcoding email address insided it"""

Can some please suggest what a best way I can use if I need to pass toaddr of multiple recipient using sys.argv?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Terry
  • 19
  • 1
  • 8

1 Answers1

0

join all addresses using ", " (comma+space) and command line argument slicing

msgRoot['To'] = ", ".join(sys.argv[2:])

(adapted from How to send email to multiple recipients using python smtplib?)

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219