#Nest NodeMailer with Send Grid

1 messages · Page 1 of 1 (latest)

neon dagger
#

We've got an email system setup with the @nestjs-modules/mailer package. For our dev env, we've got https://MailTrap.io working beautifully. Now, we need to setup a prod env mailer. We've got the Send Grid values setup, but nothing is happening. Before we throw this in prod, we're testing in dev.

For this, we aren't getting any attempts to send an email showing up as activity in Send Grid. So, I'm not sure how to debug this. Any ideas on this?

neon dagger
#

Following up. Still looking to fix this in our app.

minor storm
#

Send grid is differrent with node-mailer

#

you can use sdk of sendgrid directly,

wet pewter
#

@neon dagger I guess you're using SMTP credentials? Did you try using them somewhere else, to rule out that they are incorrect, not the code?

neon dagger
#

I'm basing my question off of the fact, that 6 years ago, I used Nodemailer with SendGrid. I did see that SendGrid has it's own package now, but I still want to use the current mailer package. We've already got it working for MailTrap, so ideally, we want to use the same package with different ENV variables for prod.

If that's not SendGrid, then I'm open to suggestions. I've got a MailGun account too if that's a better choice, but I'd still need the ability to create my own email templates with Pug.

neon dagger
#

For SendGrid use, this is pretty self-explanatory.
https://www.twilio.com/blog/send-smtp-emails-node-js-sendgrid

I've got our app setup the same, just using prod variables with the Nest flavor.

// EXAMPLE
require('dotenv').config();
const nodemailer = require("nodemailer");

let transporter = nodemailer.createTransport({
   host: 'smtp.sendgrid.net',
   port: 587,
   auth: {
       user: "apikey",
       pass: process.env.SENDGRID_API_KEY
   }
})

// OUR USE IN NEST 
MailerModule.forRoot({
  transport: {
    host: process.env.EMAIL_HOST,
    port: process.env.EMAIL_PORT,
    ignoreTLS: true,
    secure: false,
    auth: {
      user: process.env.EMAIL_USERNAME,
      pass: process.env.EMAIL_PASSWORD
    }
  },
  defaults: {
    from: `"${process.env.EMAIL_FROM}" <${process.env.EMAIL_FROM_ADDRESS}>`
  },
  template: {
    dir: `${process.cwd()}/views/emails`,
    adapter: new PugAdapter(),
    options: {
      strict: true
    }
  }
}),