简体   繁体   中英

Using a dictionary to pull Email Addresses. Some key's have multiple emails, how do I send to all emails?

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']

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM