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

142
Views
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
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!