Email Notification

Solved!
sj0071992
Email Notification

Hi,

 

I just want to check if we could sent notifications to any email id from DSS flows while it is running.

 

Thanks

0 Kudos
1 Solution
fchataigner2
Dataiker

you can add attachments with an `attachments` field/parameter. The exact structure of an attachment definition depends on the type of attachment, which you can see by creating a reporter in your scenario's settings, adding attachments in it, and checking the changes in the History tab. For example to attach a dataset named 'data' as csv.gz:

 

from dataiku.core.message_sender import MessageSender
s = MessageSender(channel_id='the_channel_id', type='mail-scenario', configuration={})
attachment = {
              "type": "DATASET",
              "params": {
                "exportParams": {
                  "selection": {
                    "samplingMethod": "FULL"
                  },
                  "format": {
                    "type": "csv",
                    "params": {
                      "style": "excel",
                      "charset": "utf8",
                      "separator": ",",
                      "quoteChar": "\"",
                      "escapeChar": "\\",
                      "parseHeaderRow": True,
                      "compress": "gz"
                    }
                  }
                },
                "attachedDataset": "data"
              }
            }
s.send(message='the info', subject='the title', recipient='to whom', attachments=[attachment])

View solution in original post

12 Replies
fchataigner2
Dataiker

Hi,

you can send messages during a scenario run with the "Send message" step. If you need to send messages from within a job (ie you can't simply make a scenario to start jobs and send messages between jobs), and the job is a Python recipe, then you can use

from dataiku.core.message_sender import MessageSender
s = MessageSender(channel_id='chan_id', type='mail-scenario', configuration={})
s.send(message='the info', subject='the title', recipient='...')

where chan_id is defined in Administration > Setttings > Notifications & Integrations 

0 Kudos
sj0071992
Author

Thanks for the reply.

 

could you please give some clarity on 

1. channel_id

2. type

3. configuration

4. recipient

It would be great if there is some link to follow

0 Kudos
fchataigner2
Dataiker

go to Administration > Settings > Notifications & Integrations and create a 'Mail (SMTP)' messaging channel at the bottom. The Id you give here is the channel_id

type is a fixed value.

configuration is a dict in which you can pass 'subject', 'recipient' and 'sendAsHTML' (a boolean). These values can also be passed as kwargs to send()

sj0071992
Author

Thanks once again.

One question where we have to define the sender?

 

0 Kudos
sj0071992
Author

Also, how can i send the data frame from Messagesender

0 Kudos
sj0071992
Author

Also, how to add multiple recipient?

0 Kudos
fchataigner2
Dataiker

about the sender: you can pass it in configuration or send(), as a sender field/parameter. But it's cleaner to set it on the message channel in Administratoition > Settings > Notificatoions & Integrations

Multiple recipients are passed as comma-separated values.

The question about dataframes is unclear: are you intending to attach a dataset to the message?

0 Kudos
sj0071992
Author

Thanks for the clarification.

 

Yes i want to attached a dataframe as csv

0 Kudos
fchataigner2
Dataiker

you can add attachments with an `attachments` field/parameter. The exact structure of an attachment definition depends on the type of attachment, which you can see by creating a reporter in your scenario's settings, adding attachments in it, and checking the changes in the History tab. For example to attach a dataset named 'data' as csv.gz:

 

from dataiku.core.message_sender import MessageSender
s = MessageSender(channel_id='the_channel_id', type='mail-scenario', configuration={})
attachment = {
              "type": "DATASET",
              "params": {
                "exportParams": {
                  "selection": {
                    "samplingMethod": "FULL"
                  },
                  "format": {
                    "type": "csv",
                    "params": {
                      "style": "excel",
                      "charset": "utf8",
                      "separator": ",",
                      "quoteChar": "\"",
                      "escapeChar": "\\",
                      "parseHeaderRow": True,
                      "compress": "gz"
                    }
                  }
                },
                "attachedDataset": "data"
              }
            }
s.send(message='the info', subject='the title', recipient='to whom', attachments=[attachment])
sj0071992
Author

I Just tried this, I am able to send the JSON in the message body of the email but still not able to send the attachment. I am using the below format,

 

attachment = {
"type": "DATASET",
"params": {
"exportParams": {
"selection": {
"samplingMethod": "FULL"
},
"format": {
"type": "csv",
"params": {
"style": "excel",
"charset": "utf8",
"separator": ",",
"quoteChar": "\"",
"escapeChar": "\\",
"dateSerializationFormat": "ISO",
"arrayMapFormat": "json"
"parseHeaderRow": True,
"compress": ""
}
}
},
"attachedDataset": "data"
}
}

0 Kudos
fchataigner2
Dataiker

by JSON, do you mean "json version of a dataframe"? Is it a pandas dataframe you're building in the python code? If so, you should have it written either to some dataset and attach the dataset with the same example as before, or dump the csv to a managed folder, and use a file-from-a-folder attachment

0 Kudos
sj0071992
Author

Let it be. Thanks for your help. It solves 90% of my problem. Rest I need to configure.

0 Kudos