Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Is there a way to get ethereal email message ID in node.js through SendGrid?

I'm currently using SendGrid as an email service in a web app, and I want to set up my dev environment to send emails to https://ethereal.email/ so I can make sure they look correct. The way I currently have it set up is I'll use nodemailer.createTestAccount() on startup, then log the credentials, then if I need to see the emails I have to manually go to the ethereal site to log in and view all the emails.

Since I'm using SendGrid to send the messages I can't just use nodemailer.getTestMessageUrl(info), but I would really like to be able to just log the URL every time an email is sent in dev then I could just go directly to the message.

I've already tried printing the SendGrid response, as well as connecting via IMAP and loading the most recent message but neither of those contain the message ID anywhere that I can see.

Is there any way to get the message ID of an email sent to ethereal.email and construct a URL directly to the message?

My environment is node.js and I'm using @sendgrid/mail to send messages.

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Twilio SendGrid developer evangelist here.

The Nodemailer documentation here suggests that you use ethereal.email as your SMTP settings in development. Then you can use nodemailer.getTestMessageUrl(info) to get the right URL.

You say you are using @sendgrid/mail to send messages, which won't respond with the URL as it is not sent out through the ethereal.email SMTP server. If you do want that URL, your best bet is to replace SendGrid in your development/test environment with ethereal.email.

You could do this by creating your own email sending objects with the same interface, one for @sendgrid/mail and one for Nodemailer with ethereal.email credentials and load the object you want based on the environment.

For example:

class SendGridEmail {
  constructor(sgApiKey) {
    // construct SG mail object
  }

  sendEmail(options) {
    // use SG mail object to send email
  }
}

class NodemailerEmail {
  constructor() {
  }

  sendEmail(options) {
  }
}

function getMailer() {
  if (process.env.NODE_ENV === "production") {
    return new SendGridEmail(process.env.SG_API_KEY);
  } else {
    return new NodemailerEmail();
  }
}

// later

getMailer().sendEmail(options);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!