> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gocopper.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Sending Email

The `cmailer` package (from [gocopper/pkg](https://github.com/gocopper/pkg)) provides a simple `Mailer` interface with two backends: AWS SES for production and a log mailer for development. To get started, install the package:

```
go get github.com/gocopper/pkg/cmailer
```

### Setup

`cmailer` does not ship a wire module, so you should provide the constructor for the backend you would like to use directly in your app's wire set:

```go pkg/app/wire.go theme={null}
var WireModule = wire.NewSet(
	// ...
	cmailer.NewLogMailer, // dev: logs emails instead of sending them
)
```

In production, you may use `cmailer.NewAWSMailer` instead and configure your SES credentials:

```toml config/prod.toml theme={null}
[aws]
region = "us-east-1"
access_key_id = "{{ .EnvVars.AWS_ACCESS_KEY_ID }}"
secret_access_key = "{{ .EnvVars.AWS_SECRET_ACCESS_KEY }}"
```

### Sending

To send an email, inject `cmailer.Mailer` wherever you need it and call its `Send` method:

```go theme={null}
err := s.mailer.Send(ctx, cmailer.SendParams{
	From:     "mission-control@rocketlog.dev",
	To:       []string{crew.Email},
	Subject:  "Launch confirmed",
	HTMLBody: cvars.Ptr("<p>Your rocket launches at T-minus 10.</p>"),
})
```

`HTMLBody` and `PlainBody` are both optional pointers, and you may set either or both. The `cvars.Ptr` helper (from `github.com/gocopper/pkg/cvars`) saves you a temporary variable.

<Note>
  The log mailer writes the full email to your app's logs, so you can develop email flows without an SES account or a real inbox.
</Note>
