← All Guides
How to Send Emails with Go
Add transactional email sending to your Go application using AISend's REST API. Simple HTTP calls, no SDK required.
1. Send with net/http
Use Go's standard library to call the AISend API:
package main
import (
"bytes"
"encoding/json"
"net/http"
)
type EmailRequest struct {
From string `json:"from"`
To string `json:"to"`
Subject string `json:"subject"`
HTML string `json:"html"`
}
func sendEmail() error {
payload := EmailRequest{
From: "hello@yourdomain.com",
To: "user@example.com",
Subject: "Hello from Go",
HTML: "<p>Sent with AISend from Go.</p>",
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://api.aisend.app/v1/emails", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer as_your_api_key")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
return nil
}