Advanced Designer Learning Path is now live! Read More

How to setup mail recipients using variables with list of email addresses in a Dataset

Level 2
How to setup mail recipients using variables with list of email addresses in a Dataset

Hi All,

I would like to seek guidance to setup a scenario that sends email to a lists of email addresses from a particular field in Dataset  as recipients (within the same projects). 

There will be different list of email address each time a job is completed. 

Some examples are greatly appreciated. Thanks.


4 Replies
Community Manager
Community Manager

Hi @thianjin we recent published a Knowledge Base article, "How to programmatically set email recipients in a "Send email" reporter using the API?" that we believe, at least in part, helps answer your question(s). 

I hope this helps and please let us know if have any further questions.

Looking for more resources to help you use DSS effectively and upskill your knowledge? Check out these great resources: Dataiku Academy | Documentation | Knowledge Base

A reply answered your question? Mark as ‘Accepted Solution’ to help others like you!
0 Kudos
Level 2

😉 It works for the most part. I had some errors when I try to alter the codes with data from DSS dataset.

# Example: load a DSS dataset as a Pandas dataframe
mydataset = dataiku.Dataset("orders")
myemail_df = mydataset.get_dataframe(columns=['customer_email'])

scenarios_list = project.list_scenarios()
#new_recipient_email_address = ""
new_recipient_email_address = myemail_df 

0 Kudos

Hi @thianjin ,

It seems that you're sending a Dataframe to a variable which expects a string.

If the list of recipients read from your dataset is exhaustive, and you don't need to preserve the list of the already existing recipients you can just convert it into a comma-separated string and replace the value of the recipient attribute of the scenario reporter that you want to update.

The code sample below will update the recipients of all the send email reporters for a specific scenario.

import dataiku

client = dataiku.api_client()

project = client.get_project("PROJECT_KEY")

mydataset = dataiku.Dataset("orders")
myemails_df = mydataset.get_dataframe(columns=['customer_email'])
myemails = ', '.join(myemails_df['customer_email'].tolist()) # Convert the Dataframe into a string of comma-separated values

scenario = project.get_scenario("SCENARIO_ID")
scenario_definition = scenario.get_definition(with_status=False)

for i in range(0, len(scenario_definition['reporters'])):
if scenario_definition['reporters'][i]['messaging']['type'] == "mail-scenario":
scenario_definition['reporters'][i]['messaging']['configuration']['recipient'] = myemails


 Have a great day!

Level 2

Thank you for helping.

Labels (2)
A banner prompting to get Dataiku DSS