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

thianjin
thianjin Registered Posts: 3 ✭✭✭

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.

Best Answer

  • dimitri
    dimitri Dataiker, Product Ideas Manager Posts: 33 Dataiker
    edited July 17 Answer ✓

    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

    scenario.set_definition(scenario_definition,with_status=False)

    Have a great day!

Answers

Setup Info
    Tags
      Help me…