NewSMTPSender (notification/email.go)

goshop · pkg/notification/email.go · go · MIT
email

A generic SMTP email sender in Go, building RFC5322 messages and supporting optional authentication.

// Source: https://github.com/quangdangfit/goshop | License: MIT | Copyright 2020 jrapoport
// Provided via justclaw.it.com; keep this notice with the code.
package notification

import (
	"bytes"
	"context"
	"errors"
	"fmt"
	"net/smtp"
	"strings"
	"text/template"
)

// EmailSender is the minimal contract an email transport must satisfy. Real implementations
// dial an SMTP server; tests can supply an in-memory fake to capture sent messages.
type EmailSender interface {
	Send(ctx context.Context, to, subject, body string) error
}

// SMTPConfig is the dial information for plain SMTP/STARTTLS. Auth is optional — leave User
// and Password empty for unauthenticated relays (e.g. MailHog in tests).
type SMTPConfig struct {
	Host     string
	Port     int
	User     string
	Password string
	From 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key