Back to blogs
Blog
Writing in public
Longer posts — published here first, then cross-posted to Dev.to with a canonical URL back to this site.
Blog
Longer posts — published here first, then cross-posted to Dev.to with a canonical URL back to this site.
Back to blogs
Back to blogs
Postsmtp, email, nodemailer, domains
odemailer with Brevo is an excellent combination for sending free emails (up to 300 per day) within...
Date published

Why You Might Still Pick Next.js Over TanStack Start From a TanStack Start...

A complete theme management system for React applications with SSR support! ✨ 🌟...

A guide to creating Android home screen widgets using Expo modules, complete with state management,...
odemailer with Brevo is an excellent combination for sending free emails (up to 300 per day) within your applications. However, a recent change implemented by Gmail and Yahoo has silently disrupted some functionality, preventing emails from reaching recipients.
To address this issue, Brevo recommends attaching a domain or subdomain to your account and verifying it. This verification process ensures compliance with the latest email sending requirements set forth by Gmail and Yahoo brevo help link.

you can now send emails like
1import { envVariables } from "@/env.ts";2import { createTransport } from "nodemailer";34export interface SendMailResponse {5 message: string;6 error: boolean;7 success: boolean;8 info: any;9}1011export interface SendEmailVersionProps {12 mail_to: string;13 mail_from: string;14 subject: string;15 body: string;16}17export async function sendEmailwithSMTP({18 subject,19 body,20 mail_from,21 mail_to,22}: SendEmailVersionProps) {23 const { BREVO_USER, BREVO_API_KEY,EMAIL_FROM } = envVariables;24 const transporter = createTransport({25 host: "smtp-relay.brevo.com",26 port: 587,27 auth: {28 // these didn't change29 // use the ones you genrated here : https://app.brevo.com/settings/keys/smtp30 user: BREVO_USER,31 pass: BREVO_API_KEY,32 },33 });34 const mailOptions = {35 subject,36 // this had to be the email you registered with brevo (still works )37 // from: "email@gmail.com",38 // but now you can also do this app-name@subdomain.domain.tld39 from: "app-name@example.com",40 // or using a subdomain from: "app-name@mail.example.com",41 // and your recipient will see the sender as app-name42 to: mail_to,43 text: body,44 };4546 async function asyncsendMail() {47 return new Promise<SendMailResponse>((resolve) => {48 transporter.sendMail(mailOptions, (error: any, info: any) => {49 if (error) {50 resolve({51 message: "Something went wrong",52 error: info,53 info,54 success: false,55 });56 } else {57 resolve({58 message: "Successfully sent, Thank you!",59 info,60 error: false,61 success: true,62 });63 }64 });65 });66 }6768 return asyncsendMail();69}70