This repository contains a Email function written in Python using SendGrid API, a MJML transpiler [https://pypi.org/project/mjml-python/] and minimum part of the Django template language. 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.
- You need a DigitalOcean account. If you don't already have one, you can sign up at https://cloud.digitalocean.com/registrations/new.
- You need a SendGrid account. If you don't already have one, you can sign up at https://signup.sendgrid.com/.
- You need to add your
SENDGRID_API_KEY
to the.env
file to connect to the SendGrid API. - To send emails with valid email addresses, you have to set up sender authentication. You can learn more at https://docs.sendgrid.com/glossary/sender-authentication.
- To send emails to email address with DMARCS, you have to set up domain authentication. You can learn more at https://docs.sendgrid.com/ui/account-and-settings/how-to-set-up-domain-authentication.
- To deploy from the command line, you will need the DigitalOcean
doctl
CLI.
Clone it and modify it to your taste...
# deploy the project, using a remote build so that compiled executable matched runtime environment
> doctl serverless deploy fn-py-mailer --remote-build
Deploying 'fn-py-mailer'
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):
- channelin/emails
Below is OBSOLETE usage from DigitalOcean's sample
doctl serverless functions invoke channelin/emails -p from:user@do.com to:user@gmail.com subject:Sammy content:Good Morning from Sammy.
{
"body": "email sent"
}
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!"}'
You can learn more about Functions and App Platform integration in the official App Platform Documentation.