Using Email in Jupyter Workspace - Python Scripts

Options

Hi All,
I was trying to trigger and send emails from the Jupyter workspaces. I have the list of emails to whom I need to send and I also have the subject and body of the email ready, but I'm not able to connect to the DOMO Notifications Email which is being used by Card alerts and Workflows to send out emails. Is there any way to not use our internal SMTP servers and instead try to use the email which is used by DOMO for notifications.

Best Answer

  • ArborRose
    ArborRose Coach
    Answer ✓
    Options

    I don't believe Domo has a direct API or method specifically for accessing its email notifications. I have sent emails using pydomo. I downloaded the information from a dataset to do a mail merge with my body. But as you are trying to avoid, it had to use my own smtp server.

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

Answers

  • ArborRose
    ArborRose Coach
    Answer ✓
    Options

    I don't believe Domo has a direct API or method specifically for accessing its email notifications. I have sent emails using pydomo. I downloaded the information from a dataset to do a mail merge with my body. But as you are trying to avoid, it had to use my own smtp server.

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • MadhavRathi
    Options

    Hi Arbor, Thanks for sharing your experience. Can you share your code snippet which worked for you using pydomo, it could be extremely helpful for me.
    Also, do you have any idea on the domo library that is available in the Jupyter script which we use to get the input/output data? I am not sure if that would help or not, but I feel there might be something that could help us connect to the Notifications EMAIL of domo to be used within the script.

  • ArborRose
    Options

    I don't have code to do a merge. But I can show you code for pulling down a domo dataset. And another for sending email.

    Generically its supposed to be something like this for pulling down a dataset.

    import requests

    Set up authentication

    client_id = 'your_client_id'
    client_secret = 'your_client_secret'
    base_url = 'https://api.domo.com' # Domo API base URL

    Get an access token

    token_url = 'https://api.domo.com/oauth/token'
    payload = {
    'client_id': client_id,
    'client_secret': client_secret,
    'grant_type': 'client_credentials'
    }
    response = requests.post(token_url, data=payload)
    access_token = response.json()['access_token']

    Example: Fetching a dataset

    dataset_id = 'your_dataset_id'
    dataset_url = f'{base_url}/v1/datasets/{dataset_id}/data'
    headers = {
    'Authorization': f'Bearer {access_token}',
    'Content-Type': 'application/json'
    }
    response = requests.get(dataset_url, headers=headers)

    Process the response

    if response.status_code == 200:
    data = response.json()
    print(data)
    else:
    print(f'Failed to fetch dataset. Status code: {response.status_code}')

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • ArborRose
    Options

    I hope I'm not including any of my private values in this. {cringe} The comment box reacts to the # symbols and such. So I will paste images.

    This code will download a file using the dataset's id set in the variable dataset_id. Id is found in the URL when you open a dataset in your browser. This code uses a Base64 version of the id + secret. Your file path needs to have double backslashes as shown. Replace myFilename.csv with your filename.

    That basically loads your data for use or saving. The following shows a python routine for sending an email.

    The task here is pull the data for use. Cycle through the records for the user list. And use the send_email function to send the emails out as it loops through the records.

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • MadhavRathi
    Options

    Thankyou so much Arbor. It is going to be really really helpful!

  • ArborRose
    Options

    I'm suspicious of any code that isn't my own. But there's a site that can help with the Base64 conversion if you can't make it happen in your own code.

    https://www.base64encode.org

    The following may be useful…

    To get the client id and secret for your instance go to developer.domo.com.

    Steps for getting the Client ID and Secret

    1. Click on the question mark at lower left corner of your Domo Instance after you have logged in to your Domo Instance
    2. Click Resources > developer portal
    3. Click on My account at right upper corner > create a new client and give all permission to that client
    4. Once you click create client button you will be shown your client Id and secret

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **