Quick setup examples
Go
Send your first email from Go using net/http against the MailBlastr API.
MailBlastr has no Go SDK — you send email by POSTing JSON to https://api.mailblastr.com/emails. The example below uses the standard-library net/http and encoding/json, so there are no third-party dependencies.
Prerequisites
- A MailBlastr API key.
- A verified domain to send from.
1. Set your API key
.env
MAILBLASTR_API_KEY=mb_xxxxxxxxx2. Send email using HTML
The easiest way to send an email is with the html field.
main.go
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
payload, _ := json.Marshal(map[string]any{
"from": "Acme <onboarding@yourdomain.com>",
"to": []string{"delivered@example.com"},
"subject": "Hello from Go",
"html": "<strong>hello world</strong>",
})
req, _ := http.NewRequest("POST", "https://api.mailblastr.com/emails", bytes.NewReader(payload))
req.Header.Set("Authorization", "Bearer "+os.Getenv("MAILBLASTR_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err.Error())
return
}
defer res.Body.Close()
var out struct {
ID string `json:"id"`
}
json.NewDecoder(res.Body).Decode(&out)
fmt.Println(out.ID)
}Drop this into a Chi or Gin handler to send from a web request. See Send an email for
cc, bcc, reply_to, and more.