Send transactional emails with MailPace
MailPace sends your application’s transactional emails, such as password resets or notifications, from a domain you own. Your application sends them over the MailPace HTTP API or SMTP, from any language. MailPace doesn’t accept newsletters or bulk marketing emails.
Create the add-on
In the Console, create a MailPace add-on, choose its plan, then link it to your applications. Plans set the number of emails per month, from 1,000 with the Solo plan. With Clever Tools, from a folder linked to your application, set its alias with --link:
clever addon create mailpace my-mail --plan clever_solo --link my-app
clever restartThe add-on is then created in the organisation of the application and linked to it. The linked applications receive the API key of the add-on in MAILPACE_API_KEY. Linking an add-on doesn’t redeploy an application: restart it to receive the variable.
Verify your domain
MailPace only sends emails once it has verified your domain. Open the Dashboard tab of the add-on in the Console and enter your domain. MailPace then shows a DKIM record to create at your DNS provider: a TXT record named ohmysmtp._domainkey, with the provided contents. Once it’s published, click Verify followed by your domain name. MailPace indicates that verification can take up to 48 hours after the DNS update.
Until then, MailPace refuses each email with Domain DKIM DNS not verified, please complete DKIM Verification. It also refuses a From address outside the domain of the API key. To also set a custom Return-Path, follow the MailPace verification guide.
Send with the HTTP API
Send an email with a POST request to the MailPace API, with the API key in the MailPace-Server-Token header. From your application, MAILPACE_API_KEY is already set. Replace the sender with an address on your verified domain, and the recipient with your test mailbox:
curl -X POST https://app.mailpace.com/api/v1/send \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "MailPace-Server-Token: $MAILPACE_API_KEY" \
-d '{"from":"hello@example.com","to":"customer@example.org","subject":"Welcome","textbody":"Thanks for signing up."}'MailPace answers {"id":49593530,"status":"queued"}: it accepted the email, which doesn’t yet mean the recipient received it. The API reference describes the other fields, such as htmlbody or attachments. To retry a request without sending the email twice, reuse the same Idempotency-Key with the same API key within 24 hours.
Send over SMTP
Configure your application or its email library with these settings:
| Setting | Value |
|---|---|
| Host | smtp.mailpace.com |
| Port and encryption | 465 with TLS, or 587, 2525, or 25 with STARTTLS |
| Username and password | The value of MAILPACE_API_KEY, for both |
The From address of each email must use your verified domain.
Send from your application
Use an SMTP library with the settings above, or one of the MailPace libraries. In these examples, use the value of MAILPACE_API_KEY as the API key, replace the sender with an address on your verified domain, and the recipient with your test mailbox:
In your Go module, add the MailPace package with go get github.com/mailpace/gomailpace, then send an email through the API:
package main
import (
"context"
"log"
"os"
"github.com/mailpace/gomailpace"
)
func main() {
client := gomailpace.NewClient(os.Getenv("MAILPACE_API_KEY"))
err := client.Send(context.Background(), gomailpace.Payload{
From: "hello@example.com",
To: "customer@example.org",
Subject: "Welcome",
TextBody: "Thanks for signing up.",
})
if err != nil {
log.Fatal(err)
}
}The MailPace documentation covers the libraries for other languages.
Track your emails
Open the Dashboard tab of the add-on to review the emails your applications sent and their statuses. To receive these statuses in your application, configure MailPace webhooks: delivered means the server of the recipient accepted the email, not that it reached the inbox.