> A raven sent from Valhalla reaches its destination. The sender does not wait at the window.
`code.nochebuena.dev/einherjar/smtp` is the email sender component of the Einherjar framework. It is built entirely on the Go standard library (`net/smtp`, `mime/multipart`, `html/template`) with no external dependencies. When `EINHERJAR_SMTP_HOST` is empty, `New` returns a silent no-op — email absence never blocks a transaction, user registration, or order placement. Health priority is `LevelDegraded`.
When `cfg.Host` is empty, `New` returns a no-op that logs every `Send` call at debug level and always returns nil. No code changes are needed between environments.
### Sending a plain-text email
```go
err:=mailer.Send(ctx,smtp.Message{
To:[]string{"user@example.com"},
Subject:"Welcome to the service",
Body:"Your account is ready.",
})
```
### Sending HTML with attachments
```go
err:=mailer.Send(ctx,smtp.Message{
To:[]string{"user@example.com"},
CC:[]string{"support@example.com"},
BCC:[]string{"audit@example.com"},// envelope only — never in headers
Subject:"Your invoice",
Body:renderedHTML,
ContentType:"text/html",
Attachments:[]smtp.Attachment{
{
Name:"invoice.pdf",
ContentType:"application/pdf",
Data:pdfReader,// consumed once; do not reuse
},
},
})
```
### Template rendering
Template rendering is intentionally separate from `Send`. Render to a string first, then assign to `Message.Body`. This keeps the transport and rendering concerns independent.