All guides
Send Email from Gin
Send emails from Gin HTTP handlers
1. Install the SDK
go get github.com/sendpigeon/sendpigeon-go2. Set your API key
Add your SendPigeon API key to your environment variables:
SENDPIGEON_API_KEY=your_api_key_hereGet your API key from the dashboard.
3. Send your first email
package main
import (
"net/http"
"os"
"github.com/gin-gonic/gin"
"github.com/sendpigeon/sendpigeon-go/sendpigeon"
)
func main() {
client := sendpigeon.New(os.Getenv("SENDPIGEON_API_KEY"))
r := gin.Default()
r.POST("/contact", func(c *gin.Context) {
var req struct {
Email string `json:"email"`
Name string `json:"name"`
}
c.BindJSON(&req)
client.Send(c.Request.Context(), sendpigeon.SendEmailRequest{
To: []string{req.Email},
From: "hello@yourdomain.com",
Subject: "Thanks for reaching out, " + req.Name + "!",
HTML: "<h1>We got your message</h1><p>We'll get back to you soon.</p>",
})
c.JSON(http.StatusOK, gin.H{"success": true})
})
r.Run(":3000")
}Features
- Context-aware requests
- High performance
- Middleware support
Ready to send emails?
Get started with 1,000 free emails per month.
Start for free