Newman is the postal worker that lives down the hall, delivering your email like a ring-tailed lemur. The newman project allows you to send emails using different email providers such as Resend, mailgun, etc.
This project is organized into several sub-packages:
- providers: managing various email providers
- credentials: managing email credentials
- shared: utilities and types
- scrubber: sanitizing email content
- Send emails using various providers
- Support for attachments and both plain text and HTML content
- Scrubber / sanitization for not getting hex0rz
Prereqs:
- Go 1.22+
- Access to the relevant email service provider (Resend is our choice!) to get credentials and such
go get github.com/theopenlane/newman
Additionally, you'll need to import the desired provider package and create an instance of the email sender then call the sendemail
function
package main
import (
"context"
"log"
"github.com/theopenlane/newman"
"github.com/theopenlane/newman/providers/resend"
)
func main() {
sender, err := resend.New(token, opts...)
if err != nil {
log.Fatal(err)
}
msg := newman.NewEmailMessageWithOptions(
newman.WithFrom("[email protected]"),
newman.WithTo([]string{"[email protected]"}),
newman.WithSubject("Isn't sending emails with golang fun?"),
newman.WithHTML("<p>Oh Yes! Mark my words, Seinfeld! Your day of reckoning is coming</p>"),
)
if err := sender.SendEmail(msg); err != nil {
log.Fatal(err)
}
}
To switch to development an just log the email to a file instead of sending an email you can use the mock
provider. With the resend
provider, this is made easy with the WithDevMode
option
sender, err := resend.New("", resend.WithDevMode("emails"))
if err != nil {
log.Fatal(err)
}
This will put the emails that would be send in the emails/
directory instead
This package supports various email providers and can be extended to include more. NOTE: we use Resend for our production service and will invest in that provider more than others.
- Resend
- Gmail
- SendGrid
- Mailgun
- Postmark
- SMTP
See the contributing guide for more information.