# Custom SMTP Deep Dive {#custom-smtp-deep-dive}


Configure custom SMTP settings for email delivery.


## Configuration {#configuration}



### Environment Variables {#environment-variables}


```env
MAIL_FROM_ADDRESS=noreply@your-company.com
MAIL_HOST=smtp.your-provider.com
MAIL_PORT=587
MAIL_USERNAME=your-smtp-username
MAIL_PASSWORD=your-smtp-password
```


### NestJS Mailer Configuration {#nestjs-mailer-configuration}


```typescript
MailerModule.forRootAsync({
  useFactory: (config: ConfigService) => ({
    transport: {
      host: config.get("MAIL_HOST"),
      port: config.get("MAIL_PORT", 587),
      secure: config.get("MAIL_PORT") === 465,
      auth: {
        user: config.get("MAIL_USERNAME"),
        pass: config.get("MAIL_PASSWORD"),
      },
    },
    defaults: {
      from: `"${config.get("APP_NAME", "Gauzy")}" <${config.get("MAIL_FROM_ADDRESS")}>`,
    },
  }),
  inject: [ConfigService],
});
```


## Popular SMTP Providers {#popular-smtp-providers}


| Provider      | Host                            | Port | Notes            |
| ------------- | ------------------------------- | ---- | ---------------- |
| Gmail         | smtp.gmail.com                  | 587  | App password req |
| SendGrid      | smtp.sendgrid.net               | 587  | API key as pass  |
| AWS SES       | email-smtp.region.amazonaws.com | 587  | IAM credentials  |
| Mailgun       | smtp.mailgun.org                | 587  | Domain verified  |
| Microsoft 365 | smtp.office365.com              | 587  | Modern auth      |


## Testing SMTP {#testing-smtp}


```bash
# Test via CLI
echo "Test" | mail -s "Test" -S smtp=smtp://smtp.example.com:587 user@example.com

# Or use the Gauzy admin panel:
# Settings → Email → Test Connection
```


## Troubleshooting {#troubleshooting}


| Issue              | Solution                         |
| ------------------ | -------------------------------- |
| Connection timeout | Check firewall rules             |
| Auth failed        | Verify credentials, app password |
| TLS errors         | Use port 587 with STARTTLS       |
| Emails in spam     | Configure SPF, DKIM, DMARC       |
| Rate limiting      | Use dedicated SMTP service       |


## DNS Records {#dns-records}


For deliverability, configure:

```
# SPF
v=spf1 include:_spf.google.com ~all

# DKIM
selector._domainkey.your-domain.com

# DMARC
_dmarc.your-domain.com  v=DMARC1; p=quarantine; rua=mailto:admin@your-domain.com
```


## Related Pages {#related-pages}


- [Email Templates](https://sourcey-gauzy.pages.dev/features/email-templates-deep-dive/index.md) — templates
- [Notification System](https://sourcey-gauzy.pages.dev/features/notification-system/index.md) — notifications
- [Environment Variables](https://sourcey-gauzy.pages.dev/reference/environment-variables/index.md) — all env vars
