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

email

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 16 Imported by: 0

README

email

Sends the transactional emails auth generates: welcome, verification, password reset, invitation.

No SMTP code lives in this plugin. It listens on the lifecycle hooks, builds the message, and hands it to whatever bridge.Mailer you configured on the engine. Swapping SendGrid for Postmark is an engine-level change and this plugin never notices.

It is the simple option. If you need locales, templates managed outside the codebase, or delivery over channels other than email, use notification instead.

Use it when

  • You want auth emails working with one plugin and a mailer, no template system to learn
  • Email is your only channel and English is your only locale
  • You are getting started and want something correct now, replaceable later

Skip it when

  • You need multiple locales or channels. notification handles both and this plugin does not
  • Your marketing team owns email templates in a tool they will not give up
  • You are already running notification. Running both means two systems trying to send the same welcome message

Wiring

authsome.WithMailer(myMailer),
authsome.WithPlugin(email.New(email.Config{
    From:    "noreply@example.com",
    AppName: "My App",
    BaseURL: "https://example.com",
})),

BaseURL is what links in the emails are built from, so it has to be the URL users reach you on, not your internal service address.

Config

Field Type Default What it does
From string noreply@authsome.local Sender address
AppName string AuthSome Name used in subjects and bodies
BaseURL string empty Root URL for building links

Settings

Key Default
email.from_address noreply@authsome.local
email.app_name AuthSome
email.base_url empty

Lifecycle hooks

Hook What happens
AfterSignUp Sends the welcome and verification email
AfterUserCreate Sends the welcome email for a user created outside signup

notification is the richer alternative. magiclink brings its own Mailer for link delivery.

Documentation

Overview

contract.go: Wires the email plugin into the forge-dashboard contract surface. The manifest + handlers live in the subpackage at plugins/email/contract/; this file exposes the integration via plugin.ContractContributor so authsome's RegisterContractContributor loop picks the plugin up automatically.

Package email provides transactional email notifications for AuthSome.

The email plugin listens to auth lifecycle events (sign-up, user creation, password reset, invitation) and sends contextual transactional emails via the bridge.Mailer interface. No SMTP logic lives here — the plugin delegates all delivery to whatever Mailer implementation the host app configures.

Usage:

eng, _ := authsome.NewEngine(
    authsome.WithStore(store),
    authsome.WithMailer(myMailer),
    authsome.WithPlugin(email.New(email.Config{
        From:    "noreply@example.com",
        AppName: "My App",
        BaseURL: "https://example.com",
    })),
)

Index

Constants

This section is empty.

Variables

View Source
var (
	// SettingFromAddress controls the default sender email address.
	SettingFromAddress = settings.Define("email.from_address", "noreply@authsome.local",
		settings.WithDisplayName("From Address"),
		settings.WithDescription("Default sender email address for outgoing emails"),
		settings.WithCategory("Email"),
		settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp),
		settings.WithInputType(formconfig.FieldEmail),
		settings.WithPlaceholder("noreply@example.com"),
		settings.WithHelpText("The sender address shown in outgoing emails"),
		settings.WithOrder(10),
	)

	// SettingAppName controls the application name used in email templates.
	SettingAppName = settings.Define("email.app_name", "AuthSome",
		settings.WithDisplayName("Application Name"),
		settings.WithDescription("Application name used in email subjects and bodies"),
		settings.WithCategory("Email"),
		settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp),
		settings.WithPlaceholder("My App"),
		settings.WithHelpText("Used in email templates for branding"),
		settings.WithOrder(20),
	)

	// SettingBaseURL controls the application root URL for email links.
	SettingBaseURL = settings.Define("email.base_url", "",
		settings.WithDisplayName("Base URL"),
		settings.WithDescription("Application root URL for building links in emails"),
		settings.WithCategory("Email"),
		settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp),
		settings.WithInputType(formconfig.FieldURL),
		settings.WithPlaceholder("https://example.com"),
		settings.WithHelpText("Used to build verification and action links in emails"),
		settings.WithOrder(30),
	)
)

Functions

func InvitationEmail

func InvitationEmail(inviterName, orgName, appName, acceptURL string) (subject, html, text string)

InvitationEmail returns an organization invitation email.

func PasswordResetEmail

func PasswordResetEmail(name, appName, resetURL string) (subject, html, text string)

PasswordResetEmail returns a password reset email.

func VerificationEmail

func VerificationEmail(name, appName, verifyURL string) (subject, html, text string)

VerificationEmail returns an email verification message.

func WelcomeEmail

func WelcomeEmail(name, appName string) (subject, html, text string)

WelcomeEmail returns a welcome email for a newly registered user.

Types

type Config

type Config struct {
	// From is the default sender email address (e.g. "noreply@example.com").
	From string

	// AppName is used in email subjects and bodies (e.g. "My App").
	AppName string

	// BaseURL is the application root URL for building links in emails
	// (e.g. "https://example.com").
	BaseURL string
}

Config configures the email notification plugin.

type Plugin

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

Plugin is the email notification plugin.

func New

func New(cfg ...Config) *Plugin

New creates a new email plugin with the given configuration.

func (*Plugin) DeclareSettings

func (p *Plugin) DeclareSettings(m *settings.Manager) error

DeclareSettings implements plugin.SettingsProvider.

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns the plugin name.

func (*Plugin) OnAfterSignUp

func (p *Plugin) OnAfterSignUp(ctx context.Context, u *user.User, _ *session.Session) error

OnAfterSignUp sends a welcome email to the newly registered user.

func (*Plugin) OnAfterUserCreate

func (p *Plugin) OnAfterUserCreate(ctx context.Context, u *user.User) error

OnAfterUserCreate sends a verification email to the newly created user.

func (*Plugin) OnInit

func (p *Plugin) OnInit(_ context.Context, engine plugin.Engine) error

OnInit extracts the mailer bridge from the engine during initialization.

func (*Plugin) RegisterContract

func (p *Plugin) RegisterContract(
	d *dispatcher.Dispatcher,
	reg contract.Registry,
	wreg contract.WardenRegistry,
	engine plugin.Engine,
) error

RegisterContract implements plugin.ContractContributor. Type-asserts the engine handle to *authsome.Engine and delegates to the subpackage.

func (*Plugin) SendInvitation

func (p *Plugin) SendInvitation(ctx context.Context, email, inviterName, orgName, acceptURL string) error

SendInvitation sends an organization invitation email.

func (*Plugin) SendPasswordReset

func (p *Plugin) SendPasswordReset(ctx context.Context, email, name, resetURL string) error

SendPasswordReset sends a password reset email. This is typically called by the engine's password reset flow.

func (*Plugin) SetMailer

func (p *Plugin) SetMailer(m bridge.Mailer)

SetMailer allows direct mailer injection for testing.

Directories

Path Synopsis
Package contract wires the email plugin's deep-link settings page into the forge-dashboard contract registry.
Package contract wires the email plugin's deep-link settings page into the forge-dashboard contract registry.

Jump to

Keyboard shortcuts

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