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

144
Visualizações
Setting nodemailer from address using request data

When nodemailer sends out an email from a contact form, it goes to an admin, who then responds to the email address found in req.body.email

I'd like to set the reply-to address as this value, so that the admin can simply hit reply to send a reply with the message data, without having to copy paste the email into the 'to' field. Here's what I've got:

Send email util

  const sendEmail = async options => {
  const transporter = nodemailer.createTransport({
    host: process.env.SMTP_HOST,
    port: process.env.SMTP_PORT,
    auth: {
      user: process.env.SMTP_EMAIL,
      pass: process.env.SMTP_PASSWORD
    }
  });

  // send mail with defined transport object
  let message = {
    // from: `${options.fromName} <${process.env.FROM_EMAIL}>`,
    from: `${options.fromName} <${options.fromEmail}>`,
    to: options.email,
    subject: options.subject,
    text: options.message,
    html: options.body
  };

  const info = await transporter.sendMail(message);

  console.log('Message sent: %s', info.messageId);
};

module.exports = sendEmail;

Send email function

  try {
    await sendEmail({
      fromName: emailBody.name,
      fromEmail: emailBody.email,
      email: 'admin@email.com',
      subject: `${emailBody.name} sent a message!`,
      body: emailBodyText
    });
  } catch (err) {
    console.log(err);
    return next(new ErrorResponse('Email could not be sent', 500));
  }

Here's what I get:

response: '553 5.7.1 <user@gmail.com>: Sender address rejected: not owned by user admin@email.com'

I get that admin@email.com cannot send email from user@gmail.com, but I'd like to have that ux of being able to simply hit reply and have the email directed to the user. Is there a good way to make it work like this?

about 4 years ago · Juan Pablo Isaza
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