How to send an email from a plugin scenario step using the Python API (Messaging Channels)?

Hi everyone,
I’m building a custom scenario step plugin in DSS 12.2.
The step collects scenario information from multiple projects, generates an HTML report, and saves it as a project variable.
Now, I would like the same plugin step to send this HTML report as an email using an existing Messaging Channel (configured in DSS under Administration → Messaging Channels), without using smtplib
or raw requests
calls.
According to the Messaging Channels API documentation, there should be a way to do something like:
project = client.get_project("MYPROJECT")
channel = project.get_messaging_channel("my-mail-channel-id")
channel.send(
to=["user@example.com"],
subject="My report",
body=table_html,
plain_text=False
)
However, when I try to call client.get_messaging_channel(...)
I get:
AttributeError: 'DSSClient' object has no attribute 'get_messaging_channel'
and I can’t find any working method from the DSSProject
object either in DSS 12.2.
My question:
What is the correct way (and method names) to access and send emails via Messaging Channels from within a Python plugin scenario step in DSS 12.3? Is this feature available from the DSSProject
object, or is it only exposed via the REST API?
Thanks in advance for any pointers!
Best regards,
Islam
Operating system used: RHEL
Best Answers
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,574 Neuron
The get_messaging_channel() is part of the client object not the project object. Here is a full sample:
import dataiku
client = dataiku.api_client()
mail_channel = client.get_messaging_channel("my-mail-channel-id")
mail_channel.send(project_key=client.get_default_project().project_key, to=["someone@something.com"], subject="Hello there!", body="‹html><body›Some HTML body</body></html>", attachments=None, plain_text=False, sender=None, cc=None, bcc=None)PS: The documentation link you referenced uses the "latest" documentation which means it's for v14 not v12. Here is the correct link for v12:
-
Hello thanks for the information i am using 12.3.1 I think it is not something possible to do from the documentation
i have this issue when i run the python code:
111 # 4. Envoi email 112 if MAIL_CHANNEL_ID and DESTINATAIRES:--> 113 channel = client.get_messaging_channel(MAIL_CHANNEL_ID) 114 channel.send( 115 project_key=client.get_default_project().project_key, AttributeError: 'DSSClient' object has no attribute 'get_messaging_channel' A handle to interact with an email messaging channel on the DSS instance - a subclass of DSSMessagingChannel
my code:
if MAIL_CHANNEL_ID and DESTINATAIRES:
channel = client.get_messaging_channel(MAIL_CHANNEL_ID)
channel.send(
project_key=client.get_default_project().project_key,
to=DESTINATAIRES,
subject=f"[DSS Report] ",
body=table_html,
plain_text=False
)I think my dss API does not have that function :(
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,574 Neuron
Indeed this functionality was added on 12.6.0 which is a year old. Your v12 version is almost 2 years old and no longer being developed. In machine learning times that’s ancient. Also the current version is now 14.0.2. You need to speak with your Dataiku administrator and have them perform upgrades frequently. Dataiku is not a product that you want to install and forget. It needs frequent updates to get the new features and the best out of it. It’s a costly product. If you don’t update it you are wasting your money. Dataiku is now typically doing 2 releases a month so in two years your missed ~24 releases with hundreds of bug fixes and new features.
https://doc.dataiku.com/dss/latest/release_notes/12.html#version-12-6-0-april-3rd-2024
Answers
-
Thanks for the clarification.
Yes, I’m actually the DSS admin here — I know we’re still on 12.3.1, but in my environment upgrades are quite challenging to coordinate.
We’re planning to move forward with a version upgrade toward the end of Q4, so unfortunately I won’t be able to useget_messaging_channel()
until then.I’ll keep the implementation ready for when we move to ≥ 13.2.1.
Best regards,
Islam
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,574 Neuron
There are two ways of upgrading:
- one big upgrade every X years
- Continuos upgrades every X months
Undoubtedly option 2 is much easier and less risky as the number of changes is much smaller. As Dataiku has already moved to releasing quickly and frequently you should also move too.
Here is another way of seeing it. How do you want to pay your technical debt? All in one big ballon payment or month by month in installments?