Search code examples
node.jsgmailnodemailer

Getting "Gmail couldn't verify that mydomain.com actually sent this message (and not a spammer)" message when sending emails with nodemailer


I'm trying to send emails using nodemailer using

  let transporter = nodemailer.createTransport({
    host: 'mail.hover.com',
    port: 465,
    secure: true, // true for 465, false for other ports
    auth: {
      user: 'myemail@mydomain.com', 
      pass: 'password', 
    },
  });

  // send mail with defined transport object
  let info = await transporter.sendMail({
    from: {
      name: 'My name',
      address: 'myemail@mydomain.com',
    }, // sender address
    replyTo: 'myemail@mydomain.com',
    to: 'recipient@gmail.com', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world?', // plain text body
    html: '<b>Hello world?</b>', // html body
  });

This sends the email as intended, but Gmail gives a warning that "Gmail couldn't verify that mydomain.com actually sent this message (and not a spammer)". I was wondering if there was a way to send the email in such a way that Gmail would know that myemail@mydomain.com actually sent the email.

Thanks!


Solution

  • Found a solution. I essentially allowed emails from my to be sent from my custom email. I followed the guide here: https://support.google.com/mail/answer/22370?hl=en.

    1. Open Gmail.

    2. In the top right, click Settings Settings and then See all settings.

    3. Click the Accounts and import or Accounts tab.

    4. In the "Send mail as" section, click Add another email address.

    5. Enter your name and the address you want to send from (my custom email).

    6. Click Next Step and then Send verification.

    7. For the SMTP server, I put mail.hover.com (since that's what I'm using)

    8. Sign in to my custom domain and click the verification link

    9. Send Email using NodeMailer

      let transporter = nodemailer.createTransport({
          host: 'smtp.gmail.com',
          port: 465,
          secure: true,
          auth: {
            user: 'mygmailuser@gmail.com', 
            pass: 'password', 
          },
        });
      let info = await transporter.sendMail({
          from: {
            name: 'My name',
            address: 'myemail@mydomain.com',
          },
          to: 'recipient@gmail.com', 
          subject: 'Hello ✔', 
          text: 'Hello world?', 
          html: '<b>Hello world?</b>',
        });