cmailer package (from gocopper/pkg) provides a simple Mailer interface with two backends: AWS SES for production and a log mailer for development. To get started, install the package:
Setup
cmailer does not ship a wire module, so you should provide the constructor for the backend you would like to use directly in your app’s wire set:
pkg/app/wire.go
cmailer.NewAWSMailer instead and configure your SES credentials:
config/prod.toml
Sending
To send an email, injectcmailer.Mailer wherever you need it and call its Send method:
HTMLBody and PlainBody are both optional pointers, and you may set either or both. The cvars.Ptr helper (from github.com/gocopper/pkg/cvars) saves you a temporary variable.
The log mailer writes the full email to your app’s logs, so you can develop email flows without an SES account or a real inbox.