Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda