# Mail

Managed email sending via SMTP.

```hcl
mail "notifications" {}
```

Reference mail attributes in env blocks:

```hcl
service "api" {
  build = build.api
  command = "./api"

  endpoint {
    public = true
  }

  env = {
    SMTP_HOST     = mail.notifications.host
    SMTP_PORT     = mail.notifications.port
    SMTP_USER     = mail.notifications.user
    SMTP_PASSWORD = mail.notifications.password
    MAIL_FROM     = mail.notifications.from
  }
}

mail "notifications" {}
```

## Available mail attributes

- `host` - SMTP server hostname
- `port` - SMTP server port
- `user` - SMTP authentication username
- `password` - SMTP authentication password
- `from` - Default sender address

## Development

In development, emails are captured by a local SMTP server and displayed in the admin dashboard under the Mail tab. No emails are actually sent.

## Example using Nodemailer (JavaScript)

```javascript
import nodemailer from "nodemailer";

const transporter = nodemailer.createTransport({
  host: process.env.SMTP_HOST,
  port: Number(process.env.SMTP_PORT),
  secure: false,
  auth: {
    user: process.env.SMTP_USER,
    pass: process.env.SMTP_PASSWORD,
  },
});

await transporter.sendMail({
  from: process.env.MAIL_FROM,
  to: "user@example.com",
  subject: "Welcome!",
  text: "Thanks for signing up.",
  html: "<p>Thanks for signing up.</p>",
});
```
