Skip to main content

Custom SMTP Deep Dive

Configure custom SMTP settings for email delivery.

Configuration

Environment Variables

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

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],
});
ProviderHostPortNotes
Gmailsmtp.gmail.com587App password req
SendGridsmtp.sendgrid.net587API key as pass
AWS SESemail-smtp.region.amazonaws.com587IAM credentials
Mailgunsmtp.mailgun.org587Domain verified
Microsoft 365smtp.office365.com587Modern auth

Testing SMTP

# 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

IssueSolution
Connection timeoutCheck firewall rules
Auth failedVerify credentials, app password
TLS errorsUse port 587 with STARTTLS
Emails in spamConfigure SPF, DKIM, DMARC
Rate limitingUse dedicated SMTP service

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