Help us shape the future of Go! Take the 2026 Go Developer Survey

smtp

package
v1.30.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package smtp delivers AuthKit's email through any SMTP server, so the provider is configuration: SendGrid (smtp.sendgrid.net, username "apikey", an API key as the password), ZeptoMail, SES or a server of your own.

email, err := smtp.New(smtp.Config{
	Server: smtp.Server{
		Host:     os.Getenv("EMAIL_SMTP_HOST"),
		Port:     587,
		Username: os.Getenv("EMAIL_SMTP_USERNAME"),
		Password: os.Getenv("EMAIL_SMTP_PASSWORD"),
		From:     "MyApp <hello@myapp.com>",
	},
	AppName: "MyApp",
})
if err != nil {
	return err
}
deps := authkit.Deps{Postgres: db, Email: email}

Each message kind renders from a built-in template in the message's Language (Spanish for "es", else English). Set Render to supply your own content for some kinds; returning false falls back to the built-in one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Server Server
	// AppName names the app in the built-in copy (default "Auth").
	AppName string
	// Render returns the content for msg, or false to use the built-in
	// template for msg.Kind.
	Render func(ctx context.Context, msg iam.EmailMessage) (Content, bool)
}

Config configures New. Server.Host and Server.From are required.

type Content

type Content struct {
	Subject string
	Text    string
	HTML    string
}

Content is one rendered email: a subject and a text or HTML body, or both.

type Email

type Email struct {
	// contains filtered or unexported fields
}

Email is an authkit.EmailSender: wire it as authkit.Deps.Email.

func New

func New(cfg Config) (*Email, error)

New validates cfg and returns an Email. It does not connect; Start's health probe does.

func (*Email) CheckHealth

func (e *Email) CheckHealth(ctx context.Context) error

CheckHealth connects, negotiates TLS and authenticates without sending: an error when the server is unreachable or refuses the credentials.

func (*Email) Send

func (e *Email) Send(ctx context.Context, msg iam.EmailMessage) error

Send renders msg (Render, else the built-in template for msg.Kind) and delivers it.

type Server

type Server = mailer.Config

Server is the SMTP server and sender (helpers/smtp.Config): Host, Port (465 implicit TLS, else STARTTLS; 0 is 587), Username, Password and From, one RFC 5322 mailbox such as "MyApp <hello@myapp.com>".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL