Create API endpoint for sending emails

NiloofarDadras
NiloofarDadras Registered Posts: 1

Hi,

I am trying to set up dataiku API to send email to custom users with custom message once endpint gets triggered. because scenarios can not run in parallel i would not be able to use the following suggestion.

https://knowledge.dataiku.com/latest/kb/o16n/automation/How-to-programmatically-set-email-recipients-in-a-reporter.html

is there any other way to get it working in Dataiku?

Tagged:

Answers

  • Sarina
    Sarina Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 317 Dataiker
    edited July 17

    Hi @NiloofarDadras
    ,

    If you want to send an email from an API endpoint, it's probably easiest to do this simply through a Python function in the API endpoint, and use Python to send the email. You can likely use the Python email package or any similar package.

    Here is an example:

    Screen Shot 2023-01-31 at 1.30.39 PM.png

    Here is the example Python function endpoint code where my SMTP server is running on 0.0.0.0:1025:

    import smtplib
    
    # Import the email modules we'll need
    from email.message import EmailMessage
    
    # Insert here initialization code
    
    # This function is the entry point for your Python function API
    # You can call this function with passing "param1", "param2",
    # "param3" as arguments to the API call
    # (see REST API documentation)
    def api_py_function():
        
        print('do some stuff')
        
        print('sending email')
        
    
        msg = EmailMessage()
        msg.set_content('Your endpoint executed with the following results...')
    
        msg['Subject'] = 'Endpoint email'
        msg['From'] = 'sarina@dataiku.com'
        msg['To'] = 'sarina@dataiku.com'
    
        # Send the message via our own SMTP server.
        s = smtplib.SMTP('0.0.0.0:1025')
        s.send_message(msg)
        s.quit()
    
        return {}
    


    Thanks,
    Sarina

Setup Info
    Tags
      Help me…