0

Using Python 2.7 on Windows 7 Platform.

I am trying to send email based on ID.
I currently have ID: Email set up in a dictionary to pull from. However some ID's have multiple emails associated. How would I set that up to send an email to each recipient. I've tried [ID]:[email, email], and it seems to only send to the first email address listed. Thanks in advance.
Dictionary creation code below.

COLS = ['rep_id', 'email', 'password']
with open('commissionrepemaillist.csv', 'r') as infile:
    email_dict = {
        row[0]: dict(zip(COLS, row)) for row in csv.reader(infile)
    }

And I'm using that to assign the variable I use to send the email

email = email_dict[ID]['email']
AlliDeacon
  • 1,365
  • 3
  • 21
  • 35

1 Answers1

1

Hard to answer with only the info given so far, but it looks like d[ID]=[email1, email2, etc] where d is your dictionary. d[ID] is a list of emails corresponding to ID. If you want to send email to a list of email addresses, this question is a good one to look at: Send Email to multiple recipients from .txt file with Python smtplib

Community
  • 1
  • 1
Riccati
  • 461
  • 4
  • 13
  • OK, well now the question has changed... Starting from `email = email_dict[ID]['email']` what is the result of `print(email)` ? – Riccati Dec 10 '15 at 20:18
  • Is `'email'` a string that appears in `COLS`? Does it appear more than once? – Riccati Dec 10 '15 at 20:25
  • I've added the definition of COLS. It's the "header" or "label" for a row in the csv file. `print email` prints the email address of the correlating ID as a string. – AlliDeacon Dec 10 '15 at 20:29
  • I think your suggested solution points me in the direction I need to be going in. Thank you. – AlliDeacon Dec 10 '15 at 20:31
  • Try `print(email)`. Should print a list of email addresses. If it does, then it sounds like the question is how to send email to a list of email addresses. The answer to that question is covered reasonably well in the linked answer given above. Or is that not the question? – Riccati Dec 10 '15 at 20:32