How do I use my email alias as original sender with GSUITE & Nodemailer?

Viewed 188

I have a form with two fields, username and email address, so users can leave their names for a reservation list for a new product coming soon.

I have properly set nodemailer with gsuite and also an alias email attached to the admin user of the gsuite account.

What I would like to know is how can I have the email alias actually appearing on the field sent on the email.

As we can see below, the email header message is correct, also if the user tries to reply, it will be to no-reply@.....

The thing is that you can notice that the user primary account offial user email, namely deboradeoliveira@.... is still there, showing up, which can lead to the users getting that email and sending emails...

Is there any way to use the email alias as the sender, or GSUIT will always show the official user primary email on this field, forcing me to pay/create a new user on the admin console just to do what I intend?

enter image description here

Below is my mailer handler:

in this case, YOUR_EMAIL_ADDRESS is this no-reply@... alias email of deboradeoliveira@....

import nodemailer from "nodemailer"

const YOUR_EMAIL_ADDRESS = process.env.MAILER_MY_EMAIL;

const transporter = nodemailer.createTransport({
    host: "smtp.gmail.com",
    port: 465,
    secure: true,
    auth: {
      type: "OAuth2",  
      user: YOUR_EMAIL_ADDRESS,
      serviceClient: process.env.MAILER_CLIENT_ID,
      privateKey: process.env.MAILER_PRIVATE_KEY
  }});

export default async (req, res) => {
    const { name, recipientMail } = req.body

    const mailerRes = await mailer({  name, recipientMail })
    res.send(mailerRes)
}

const mailer = ({  name,  recipientMail }) => {
    const message = {
        from: YOUR_EMAIL_ADDRESS,
        to: `${recipientMail}`,
        subject: `New message from ${YOUR_EMAIL_ADDRESS}`,
        replyTo: YOUR_EMAIL_ADDRESS,
        html: `<b>Hey there ${name}! </b><br> This is our first message sent with Nodemailer`
    }

    return new Promise((resolve, reject) => {
        transporter.sendMail(message, (error, info) =>
            error ? reject(error) : resolve(info)
        )
    })
}
0 Answers
Related