How to Send Jupyter Notebook Cell Output via Email or MS Teams?

I have a use case where, whenever an issue occurs, I want to execute a specific Jupyter notebook cell. After execution, I need the interactive output of the cell to be automatically sent to someone via email or MS Teams.

Could anyone advise on how to achieve this in JupyterHub? Is there a way to capture the output of a cell and send it programmatically to a recipient via email or Teams chat?

Thank you for your help!

You could write a custom JupyterLab plugin to capture the cell output:

and send it using an MSTeams or email API.

Though it’d be a lot easier to make the API call in a notebook cell instead of trying to capture the output.