Skip to content

the postal worker that lives down the hall, delivering your email like a ring-tailed lemur

License

Notifications You must be signed in to change notification settings

theopenlane/newman

Build status Quality Gate Status Go Report Card Go Reference License: Apache 2.0

newman

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.

newman

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

Features

  • Send emails using various providers
  • Support for attachments and both plain text and HTML content
  • Scrubber / sanitization for not getting hex0rz

Usage

Prereqs:

  • Go 1.22+
  • Access to the relevant email service provider (Resend is our choice!) to get credentials and such

Adding to your project

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)
    }
}

Development Mode

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

Implemented Providers

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

Contributing

See the contributing guide for more information.

About

the postal worker that lives down the hall, delivering your email like a ring-tailed lemur

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages