A developer demonstrates configuring Nodemailer in a NestJS application to send emails via Gmail SMTP using OAuth2. The process includes setting up a Google Cloud project, creating OAuth credentials, obtaining a refresh token via the OAuth playground, and updating environment variables to successfully send automated notifications.
Length 12:34
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #nodemailer #smtp #gmail #oauth2 #nestjs #email #authentication #backend #api #coding
0:00 So we're gonna use Nodmailer as our third-party package to 0:04 manage email sending in Node. Additionally, we're gonna use Gmail as our 0:08 SMTP provider because it is a free option 0:11 that will allow us to send 0:12 up to five thousand emails a day on a given account, 0:16 which will work fine for our purpose. 0:18 I'm also gonna show you how to easily configure Nodmailer to swap in your own 0:22 custom domain and your own custom SMTP server in 0:26 case you wanna pay for a third-party service that will allow you to send 0:30 more emails a day. So to get started, let's go ahead and 0:34 stop our containers, and we'll go ahead and run pnpm install 0:37 nodmailer. And additionally, make sure we install the 0:41 types for Nodmailer as well. And then we can go ahead 0:45 and start our containers back up. And I'll go ahead and declare a 0:49 new private read-only variable here called 0:52 transporter, which is gonna be equal to Nodmailer 0:56 dot. And we can go ahead and import Nodmailer up 1:00 top. So go ahead and import Nodmailer from 1:03 Nodmailer here, and then we can call 1:06 .createTransport on it. And additionally, make sure we 1:10 import star as Nodmailer from Nodmailer here to make sure 1:14 this import works properly. So in createTransport, this is where we 1:18 provide the options object where you can configure your 1:22 own SMTP server, which will be used to send 1:26 emails. So feel free to include your own 1:28 credentials or follow along with me where 1:30 we set up a free Gmail account and create our own 1:34 SMTP provider. To do that, we're gonna go ahead 1:36 and specify a service h- 1:38 property here where we say this service is Gmail, and then we 1:42 provide an auth object here. I'm gonna set the type here to 1:46 OAuth2, and then we're gonna make use of the
The rest of the transcript is for members.
Sign in