Documentation
¶
Overview ¶
Package emailmock is a dev-only implementation of email.Sender that ships messages to the hamr dev server's mail inbox at /__hamr/mail.
The mock does not construct MIME, talk SMTP, or call any provider API. It serializes the email.Message to JSON and POSTs it to the hamr dev proxy, which stores it in an in-memory inbox viewable at http://<dev-proxy>/__hamr/mail.
Because the wire format is JSON (not MIME), this mock validates how your application uses the email.Sender interface — it does not validate your production provider adapter's MIME construction or SMTP handshake. Catch those bugs with your provider's test environment or integration tests.
Typical wiring in main.go:
var sender email.Sender
if os.Getenv("EMAIL_MOCK") == "true" {
sender = emailmock.New(os.Getenv("HAMR_DEV_URL"))
} else {
sender = myapp.NewRealSender(...)
}
The mock client is safe for concurrent use.
Failure simulation: any recipient whose local-part is "bounce" (e.g. bounce@example.com) causes Send to return ErrBounced without storing the message; any recipient whose local-part is "reject" returns ErrRejected. This lets apps test error paths without configuring anything server-side.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrBounced = errors.New("emailmock: recipient bounced") ErrRejected = errors.New("emailmock: recipient rejected") )
Well-known failure outcomes returned by Send when the message hits a magic recipient. These wrap the server-side refusal so apps can test bounce and reject error paths deterministically.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a dev-only email.Sender that POSTs messages to the hamr dev server's /__hamr/mail/ingest endpoint.
func New ¶
New returns a Client that ingests messages at baseURL/__hamr/mail/ingest. baseURL is typically the hamr dev proxy origin (e.g. "http://localhost:3000"). Trailing slashes are stripped. An empty baseURL is accepted but every Send will fail until the client is re-configured.