6

I have a problem with nodemailer where the user receive the email with sent from my google account which used to authenticate gmail instead of the alias used in mail options.

Below is my code:

var smtpTransport = nodemailer.createTransport({
    service: config.mailer.options.service,
    auth: {
        user: "xxxx@gmail.com",
        pass: "password"
    }
});


var mailOptions = {
       to: user.email,
       from: 'Test Email <aaa@aaa.com>',
       subject: subject,
       html: emailHTML
};

smtpTransport.sendMail(mailOptions); Now when the user receive an email the email mentions that

from: Test Email xxxx@gmail.com

Instead of showing

from: Test Email aaa@aaa.com

Any help please

Dev
  • 1,861
  • 2
  • 14
  • 20
  • [This](http://stackoverflow.com/questions/34348413/gmail-for-business-api-doesnt-allow-to-send-email-from-alias) might be related if you are using a business account. – Tholle Jan 06 '16 at 15:13
  • @Tholle I got a response from nodemailer "Gmail always sends messages as the authenticated user. If you want to use custom address then use some other service", do you think that I can't solve this using both nodemailer and gmail API – Dev Jan 06 '16 at 16:20
  • Ah, I see :( I don't know if you can, sorry. – Tholle Jan 06 '16 at 16:54
  • Have you tried reading this? (http://adilapapaya.com/docs/nodemailer/) – Android Enthusiast Jan 07 '16 at 15:19
  • I'm looking for the solution yet - Any update – DebuggerCoder Mar 03 '17 at 06:46
  • I think that you should use gmail api only https://mail.google.com, follow steps mentioned here (http://stackoverflow.com/questions/24098461/nodemailer-gmail-what-exactly-is-a-refresh-token-and-how-do-i-get-one) – Dev Mar 04 '17 at 23:29
  • THIS SAME PROBLEM.. I ADDED SOLUTION..FIND MY ANSWER https://stackoverflow.com/questions/41418737/send-email-via-nodemailer/49557206#49557206 – BIS Tech Mar 29 '18 at 13:27

2 Answers2

3

you also need to configure the alias in your gmail account. I faced the same issue but after configuring alias in gmail it worked. check this link to configure https://support.google.com/mail/answer/22370?hl=en

0

Now, with Gmail, you can use aliases as your main account. Just go into Gmail settings under account and select default.