Survey banner
Share your feedback on the Dataiku documentation with this 5 min survey. Thanks! TAKE THE SURVEY

Use reporter in scenarios to send email notifications

Solved!
s_dravid
Level 3
Use reporter in scenarios to send email notifications

Hi,

I have made a setup of scenaios using python api to send emails based on a dataset to various recipients. My concern is that with tme the number of recipients will increase, so is there a possibility that the process may fail in between? The set up includes a base dataset, python script to set the recipient, subject and email body (all of this changes with each recipient). As of now this is working fine, but the process fails after sometime showing an error of Dataiku exception for run and wait. What could be the best way here? Also, I want to know if we can have a delivery report too so that we get to know that the email has been successfully received by the recipient.

0 Kudos
1 Solution

Also I posted a sample of how to send SMTP emails using Gmail via Python here:

https://community.dataiku.com/t5/Plugins-Extending-Dataiku/How-to-use-Send-email-plugin/m-p/35809

But you can use the same concept for a regular internal SMTP server.

View solution in original post

0 Kudos
6 Replies
AlexT
Dataiker

Hi @s_dravid ,
You may be able to use sendmail plugin for this case as well:
https://www.dataiku.com/product/plugins/sendmail/ 

But without knowing what the current scenario looks and the logs for the failure it's hard to advise. I would suggest you open a support ticket with the scenario diagnostics of the failing scenario.

Thanks,

0 Kudos
Turribeach

Can you post the code snippet of the code that geenrates the failure? 

0 Kudos
s_dravid
Level 3
Author

Hi 

So, I am using below function and calling it for the recipients.

def emails(mail_body,subject,email):

scenario_def.raw_reporters[0]['messaging']['configuration']['recipient'] = email
scenario_def.raw_reporters[0]['messaging']['configuration']['subject'] = subject
scenario_def.raw_reporters[0]['messaging']['configuration']['message'] = mail_body

scenario_def.save()
trigger=scenario.run_and_wait()

return 'success'

 

This runs fine for sometime like sending emails for few people and then it fails like for example on the 10th recipient. The error is displayed as :

"in wait_for_scenario_run raise Dataiku exception("Scenario run has been cancelled")"

Also, I would like to know if there is a way to access the plugin recipe for emails through python api.

0 Kudos

First of all you need to find out exactly why the scenario is failing. Please check the scenario logs. Secondly why do you need to use scenario.run_and_wait()? It will be better to run them asynchronously like this:

https://developer.dataiku.com/latest/concepts-and-examples/scenarios.html#variant-2-run-then-poll-wh...

Finally check that your SMTP server does not throttle clients sending too many emails as this could prevent them from going out. 

0 Kudos

Also I posted a sample of how to send SMTP emails using Gmail via Python here:

https://community.dataiku.com/t5/Plugins-Extending-Dataiku/How-to-use-Send-email-plugin/m-p/35809

But you can use the same concept for a regular internal SMTP server.

0 Kudos
s_dravid
Level 3
Author

HI @Turribeach 

The sample code helped here. I modified it as per my need and it is working much faster than using another dummy scenario for using the reporter section. Thanks for your help.

Regards

Sarthak