I have a dataframe which contains multiple columns with financial and personal information of customers and advisors. Each customer has a Financial Advisor whose email is located in the last column.
First problem I am facing is that various customers have one Financial Advisor in common so I would need a for loop to group all the customers in one email for the respective Financial Advisor.
Also, I want to select only a few columns to send the information and then send it through to the Financial Advisor's email as a table.
To illustrate:
d = {'Name': [John, Sheila, Bryan], 'Product': [Treasury Bond, Treasury Bond, Treasury Bond], 'Quantity': [10,20,30] , 'Financial Advisor's Name':[ Jack, Jack, Claudia], 'Financial Advisor's Email': [[email protected],[email protected],[email protected]]}
def create_message(send_from, send_to,subject, plain_text_body):
sender_address = "[email protected]"
mail_content="This is a test message"
for a, b, c, in zip(d['Name'], d['Product'], d['Financial Advisor's Name'], d['Quantity']):
if
message = MIMEMultipart('alternative')
message['From'] = send_from
message['To'] = COMMASPACE.join(send_to)
message['Cc'] = cc_to
message['Subject'] = subject
message.attach(MIMEText(plain_text_body, 'plain'))
return message
How do I assign the emails I have on the last column to the sender_address variable ? And how to use an If statement to send just one email to the Financial Advisor with his various customers ?
question from:
https://stackoverflow.com/questions/65888886/iterate-through-rows-and-for-each-one-send-an-email-using-the-email-on-the-last 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…