All guides

Send Email from Echo

Send emails from Echo HTTP handlers

1. Install the SDK

go get github.com/sendpigeon/sendpigeon-go

2. Set your API key

Add your SendPigeon API key to your environment variables:

SENDPIGEON_API_KEY=your_api_key_here

Get your API key from the dashboard.

3. Send your first email

package main

import (
	"net/http"
	"os"

	"github.com/labstack/echo/v4"
	"github.com/sendpigeon/sendpigeon-go/sendpigeon"
)

func main() {
	client := sendpigeon.New(os.Getenv("SENDPIGEON_API_KEY"))
	e := echo.New()

	e.POST("/contact", func(c echo.Context) error {
		var req struct {
			Email string `json:"email"`
			Name  string `json:"name"`
		}
		c.Bind(&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>",
		})

		return c.JSON(http.StatusOK, map[string]bool{"success": true})
	})

	e.Start(":3000")
}

Features

  • Minimalist design
  • Context propagation
  • Extensible middleware

Ready to send emails?

Get started with 1,000 free emails per month.

Start for free