newman

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 2

README

Build status Quality Gate Status Go Report Card Go Reference

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.24+
  • 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("no-reply@youremailaddress.com"),
        newman.WithTo([]string{"mitb@emailsendingfun.com"}),
        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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBatchNotImplemented = errors.New("batch email sending is not implemented for this provider")

ErrBatchNotImplemented is returned by providers that do not support native batch sending

Functions

func BuildMimeMessage

func BuildMimeMessage(message *EmailMessage) ([]byte, error)

BuildMimeMessage constructs the MIME message for the email, including text, HTML, and attachments

func GetMimeType

func GetMimeType(filename string) string

GetMimeType returns the MIME type based on the file extension

func IsRetryableError added in v0.2.0

func IsRetryableError(err error) bool

IsRetryableError checks if the error is retryable.

func NewRetryableError added in v0.2.0

func NewRetryableError(reason error) error

NewRetryableError creates a new retryable error with a given reason.

func ValidateEmail

func ValidateEmail(email string) string

ValidateEmail validates and sanitizes an email address

func ValidateEmailSlice

func ValidateEmailSlice(emails []string) []string

ValidateEmailSlice validates and sanitizes a slice of email addresses

Types

type Attachment

type Attachment = shared.Attachment

Attachment represents an email attachment with its filename and content

func NewAttachment

func NewAttachment(filename string, content []byte) *Attachment

NewAttachment creates a new Attachment instance with the specified filename and content

func NewAttachmentFromFile

func NewAttachmentFromFile(filePath string) (*Attachment, error)

NewAttachmentFromFile creates a new Attachment instance from the specified file path

type EmailMessage

type EmailMessage = shared.EmailMessage

EmailMessage represents an email message

func NewEmailMessage

func NewEmailMessage(from string, to []string, subject string, body string) *EmailMessage

NewEmailMessage creates a new EmailMessage with the required fields

func NewEmailMessageWithOptions added in v0.1.1

func NewEmailMessageWithOptions(options ...MessageOption) *EmailMessage

NewEmailMessageWithOptions creates a new EmailMessage with the specified options

type EmailSender

type EmailSender interface {
	// SendEmail sends an email with the given message
	SendEmail(message *EmailMessage) error
	// SendEmailWithContext sends an email with the given message and context
	SendEmailWithContext(ctx context.Context, message *EmailMessage) error
	// SendBatchEmail sends a batch of emails with the given messages
	SendBatchEmail(messages []*EmailMessage) error
	// SendBatchEmailWithContext sends a batch of emails with the given messages and context
	SendBatchEmailWithContext(ctx context.Context, messages []*EmailMessage) error
}

EmailSender interface defines the method to send an email

type MessageOption added in v0.1.1

type MessageOption func(*EmailMessage)

MessageOption is a function that sets a field on an EmailMessage

func WithAttachment added in v0.1.1

func WithAttachment(attachment *Attachment) MessageOption

WithAttachment adds an attachment to the email

func WithAttachments added in v0.1.1

func WithAttachments(attachments []*Attachment) MessageOption

WithAttachments sets the attachments of the email

func WithBcc added in v0.1.1

func WithBcc(bcc []string) MessageOption

WithBcc sets the bcc email address

func WithCc added in v0.1.1

func WithCc(cc []string) MessageOption

WithCc sets the cc email address

func WithFrom added in v0.1.1

func WithFrom(from string) MessageOption

WithFrom sets the from email address

func WithHTML added in v0.1.1

func WithHTML(html string) MessageOption

WithHTML sets the html content of the email

func WithHeader added in v0.1.1

func WithHeader(key, value string) MessageOption

WithHeader adds a header to the email

func WithHeaderMap added in v0.1.1

func WithHeaderMap(headers map[string]string) MessageOption

WithHeaderMap adds a map of headers to the email

func WithHeaders added in v0.1.1

func WithHeaders(headers map[string]string) MessageOption

WithHeaders sets the headers of the email

func WithReplyTo added in v0.1.1

func WithReplyTo(replyTo string) MessageOption

WithReplyTo sets the reply to email address

func WithSubject added in v0.1.1

func WithSubject(subject string) MessageOption

WithSubject sets the subject of the email

func WithTag added in v0.1.1

func WithTag(tag Tag) MessageOption

WithTag adds a tag to the email

func WithTags added in v0.1.1

func WithTags(tags []Tag) MessageOption

WithTags sets the tags of the email

func WithText added in v0.1.1

func WithText(text string) MessageOption

WithText sets the text content of the email

func WithTo added in v0.1.1

func WithTo(to []string) MessageOption

WithTo sets the to email address

type Tag added in v0.1.1

type Tag = shared.Tag

Tag is used to define custom metadata for message

Directories

Path Synopsis
Package credentials is a helper to load credentials for respective email providers
Package credentials is a helper to load credentials for respective email providers
Package providers are the vendor specific email senders
Package providers are the vendor specific email senders
gmail
Package gmail is used for sending emails via gmail
Package gmail is used for sending emails via gmail
mailgun
Package mailgun is used for sending emails via mailgun
Package mailgun is used for sending emails via mailgun
mock
Package mock is for mocking the sending of emails, for testing and such
Package mock is for mocking the sending of emails, for testing and such
postmark
Package postmark is used for sending emails via postmark
Package postmark is used for sending emails via postmark
resend
Package resend is for sending emails via the resend api
Package resend is for sending emails via the resend api
sendgrid
Package sendgrid is used for sending emails via sendgrid
Package sendgrid is used for sending emails via sendgrid
smtp
Package smtp is used for sending emails via smtp
Package smtp is used for sending emails via smtp
Package render provides themed email generation with CSS inlining, automatic plain text derivation, and markdown support
Package render provides themed email generation with CSS inlining, automatic plain text derivation, and markdown support
Package scrubber is designed to be used in conjunction with the newman project for flexible email content sanitization
Package scrubber is designed to be used in conjunction with the newman project for flexible email content sanitization
package shared provides utility functions and structures used across the newman project
package shared provides utility functions and structures used across the newman project

Jump to

Keyboard shortcuts

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