Sample Function: Python "Sendgrid Emails"

Introduction

This repository contains a sample Sendgrid Email function written in Python. You are able to send an email using Sendgrid's API to email addresses with or without DMARCS. You can deploy it on DigitalOcean's App Platform as a Serverless Function component. Documentation is available at https://docs.digitalocean.com/products/functions.

Requirements

Deploying the Function

# clone this repo
git clone git@github.com:digitalocean/sample-functions-python-sendgrid-email.git
# deploy the project, using a remote build so that compiled executable matched runtime environment
> doctl serverless deploy sample-functions-python-sendgrid-email --remote-build
Deploying 'sample-functions-python-sendgrid-email'
  to namespace 'fn-...'
  on host 'https://faas-...'
Submitted action 'emails' for remote building and deployment in runtime python:default (id: ...)

Deployed functions ('doctl sls fn get <funcName> --url' for URL):
  - sample/emails

Using the Function

doctl serverless functions invoke sample/emails -p from:user@do.com to:user@gmail.com subject:Sammy content:Good Morning from Sammy.
{
  "body": "email sent"
}

To send an email using curl:

curl -X PUT -H 'Content-Type: application/json' {your-DO-app-url} -d '{"from":"user@do.com", "to":"user@gmail.com", "subject": "Sammy", "content":"Good Morning from Sammy!"}' 

Learn More

You can learn more about Functions and App Platform integration in the official App Platform Documentation.

doctl serverless deploy /Users/waleedalrashed/Documents/dev/workspace/micro_services/sample-functions-python-sendgrid-email --remote-build