Add Sendgrid SMTP
Daniel Skov Jacobsen
Allow using Sendgrid SMTP by default.
Sendgrid is a great alternative to Gmail and works seamlessly with nodemailer.
It can be added by following these steps:
Add to .env
EMAIL_SENDGRID_HOST=smtp.sendgrid.net
EMAIL_SENDGRID_PORT=587
EMAIL_SENDGRID_USERNAME=apikey
EMAIL_SENDGRID_PASSWORD=
Update detect-transport.ts
Something like this.. Feel free to adjust the flow of logic, but checking it first in conf. makes good sense for me.
// Check for SendGrid configuration first
return {
host: env.EMAIL_SENDGRID_HOST,
port: parseInt(env.EMAIL_SENDGRID_PORT),
auth: {
user: env.EMAIL_SENDGRID_USERNAME || 'apikey',
pass: env.EMAIL_SENDGRID_PASSWORD
},
secure: false // SendGrid uses TLS
};
}
Update the keys.ts (createEnv)
Added the " EMAIL_SENDGRID_" prefixed keys..
createEnv({
server: {
EMAIL_FROM: z.string(), // emails can be in format "Acme <noreply@mailer.example.com>"
EMAIL_FEEDBACK_INBOX: z.string().email().optional(),
EMAIL_MAILER: z.enum(['NodeMailer', 'Resend']),
// credentials (you just need one)
EMAIL_NODEMAILER_URL: z.string().optional(),
EMAIL_RESEND_API_KEY: z.string().optional(),
EMAIL_SENDGRID_HOST: z.string().optional(),
EMAIL_SENDGRID_PORT: z.string().optional(),
EMAIL_SENDGRID_USERNAME: z.string().optional(),
EMAIL_SENDGRID_PASSWORD: z.string().optional()
},
runtimeEnv: {
EMAIL_FROM: process.env.EMAIL_FROM,
EMAIL_FEEDBACK_INBOX: process.env.EMAIL_FEEDBACK_INBOX,
EMAIL_MAILER: process.env.EMAIL_MAILER,
EMAIL_NODEMAILER_URL: process.env.EMAIL_NODEMAILER_URL,
EMAIL_RESEND_API_KEY: process.env.EMAIL_RESEND_API_KEY,
EMAIL_SENDGRID_HOST: process.env.EMAIL_SENDGRID_HOST,
EMAIL_SENDGRID_PORT: process.env.EMAIL_SENDGRID_PORT,
EMAIL_SENDGRID_USERNAME: process.env.EMAIL_SENDGRID_USERNAME,
EMAIL_SENDGRID_PASSWORD: process.env.EMAIL_SENDGRID_PASSWORD
}
And that's it, Sendgrid works.
Daniel Skov Jacobsen
If you'd like, I can provide a PR with the feature but it doesn't seem like we're allowed to send PRs atm.