11

I'm sending an email to myself using a module (nodemailer) on my web application's platform (node.js) from someone using my web app's contact page. Since, I'm sending an email to myself, if I reply to the email, I'll be sending an email to myself again, and not sending it to the email in the "from" header that's set in the email's header. How could I let clients (gmail, yahoo, etc) know which email should be replied to?

I'm using Nodemailer module for Node.js to do the sending from a Ubuntu Linux server.

Sam
  • 6,414
  • 11
  • 46
  • 61

7 Answers7

8

Usually adding a Reply-To: header will be sufficient for indicating which address replies should be sent to.

tadman
  • 208,517
  • 23
  • 234
  • 262
  • I've set Reply-To and From headers, and I confirmed they were set, in the original message option in Gmail. But, gmail still doesn't reply to these emails. – Sam May 15 '13 at 23:03
  • Can you confirm the header's showing up when the message is received? – tadman May 16 '13 at 01:22
  • This could be a quirk of Gmail and how it handles certain Reply-To addresses. [Some discussion from a while ago](http://stackoverflow.com/questions/4084079/rails-and-gmail-reply-to-function-not-working-as-hoped) might help. – tadman May 16 '13 at 02:04
4

I had exactly the same problem and found the solution in this StackOverflow thread, which pointed to this forum:

If the "From" address is either the same as the "To" address, or is configured in GMail Settings as one of the 'Send As...' accounts, Gmail replies to the "To" address instead of the "Reply-To" address. An easy workaround is to specify a non-Gmail "From" address

I wasted quite a bit of time before finding the solution. Hope this helps out other people.

Community
  • 1
  • 1
Wissam
  • 283
  • 1
  • 8
3

I don't know anything about Nodemailer, but their documentation seems to indicate that it supports setting the replyTo property - which sounds like what you want? All major email clients use an email's reply-to field to send a response if it exists.

neminem
  • 2,658
  • 5
  • 27
  • 36
  • 1
    I've set both the reply-to and from headers for the email properly, and yet gmail still replies back to the Sender header. :\ – Sam May 15 '13 at 23:02
3

You can do it easy by adding replyTo: email@email.com as a routing option to the mailOptions :

Example

var transporter = nodemailer.createTransport({
    host: "smtp.server.com",
    port: 465,
    secure: true,
    auth: {
      user: "sender@email.com",
      pass: "psw",
    },
});

const mailOptions = {
    from: "from@email.com",
    to: "to@email.com",
    subject: "New Feedback",
    replyTo: email,
    html: `
    Your email html code here .... `,
};



 transporter.sendMail(mailOptions, (error, data) => {
    console.log(data);
    if (error) {
      console.log(error); 
    } 
  });
2

Add a replyTo field to the mailOptions object. That worked for me. It's also in their docs.

The from will still show your email but replies will go to the replyTo email. Also, make sure you use the '"Fred Foo" ' syntax in the from field and you will see the sender's name on the conversation from field.

TGrif
  • 5,725
  • 9
  • 31
  • 52
Bambi
  • 123
  • 6
0

After reading all the answers, here's what worked for me:

Specify BOTH "from" and "replyTo" fields (with the email you want to reply to), not only one or the other.

This allows you to still use a Gmail account to send those messages.

Kqtr
  • 5,824
  • 3
  • 25
  • 32
  • This didn't work for me. I think the 'from' field *must* be your own email. Getting the error, `553 5.7.1 Sender address rejected: not owned by auth user.` – Mike K Aug 24 '20 at 16:35
0

I think this issue must have been fixed. I just tested it myself with the current latest nodemailer and i was able to send to myself and the replyTo was set to a different email address which worked perfectly in gmail. I just had to make sure to specify the from and to as the same email(that is my email) and then specify the reply-to as the user's email. All the email addresses were gmail addresses in this test in case someone wants to know.

"nodemailer": "^6.6.0"

that's the version of nodemailer i just tested it on.