Some Help, Tips or Any Light: I'm crazy about Strapi + NodeMailer

System Information
  • Strapi Version: 3.6.2
  • Operating System: Debian GNU / Linux 10 (buster)
  • Database: 10.5.8-MariaDB
  • Node Version: 12.20.2
  • NPM Version: 7.8.0
  • Yarn Version: 1.22.10
    -Provider: AWS LightSail Instance - 4 GB RAM, 2 vCPUs, 80 GB SSD

Hey guys,
even if I don’t have great Strapi knowledge , I’ve been working on a project to my client for about 4 months now. As a self-taught person, I have been following a rocky path with a lot of reading, research and a lot of trial and error. (English in not my native language)
But now, I need to complete my project and I am really in shock.
Could any charitable soul help me?

I thank in advance to everyone who can help me.

In development I used my own email account (domain hosted by ReselleClub) and everything worked very well!
Now, I need to use the costumer’s email account (domain hosted by HostGator) and I am unsuccessful sending messages.
In STRAPI EMAIL SETTING (Test Email) apparently the message is sent … the NodeMailer log indicates the same (I think), that is, no error message is returned / displayed, but the message is never delivered to the recipient, and the sender account does not receive any messages due to delivery problems.

The AWS LIGHTSAIL instance uses a client SUBDOMAIN with the appropriate DNS created in HostGator.

My Test SUCCESSFULLY: Using my own email account (in Development)

> plugin.js
> ----------------------------------------
>   email: {
> 	provider: 'nodemailer',
> 	providerOptions: {
> 		host: env('EMAIL_HOST','mail.MyDomain.net.br'),
>         port: env('EMAIL_PORT',587),
>         debug: true, 
>         logger: true, 
>         auth: {
> 			user: env('EMAIL_USER','hostmaster@MyDomain.net.br'),
> 			pass: env('EMAIL_PASS','MyPassword')
>         },
>         tls: {
> 			rejectUnauthorized: false
>         }
>       }, 
>       settings: {
> 		defaultFrom: env('SENDMAIL_DEFAULT_FROM','hostmaster@MyDomain.net.br'),
>         defaultReplyTo: env('SENDMAIL_DEFAULT_REPLY_TO','hostmaster@MyDomain.net.br'),
>         testAddress: env('SENDMAIL_DEFAULT_TEST_ADDRESS','MyAccount@gmail.com')
>       }
> }
> 
> The NodeMailer LOG
> ----------------------------------------
> [2021-05-24 15:13:45] DEBUG Sending mail using SMTP/6.6.0[client:6.6.0]
> [2021-05-24 15:13:45] DEBUG [UIW7kChYQ38] Resolved mail.MyDomain.net.br as 209.99.16.76 [cache miss]
> [2021-05-24 15:13:45] INFO  [UIW7kChYQ38] Connection established to 209.99.16.76:587
> [2021-05-24 15:13:45] DEBUG [UIW7kChYQ38] S: 220 DDBH-PLESK-WEB1.webhostbox.net ESMTP MailEnable Service, Version: 10.31-10.31- ready at 05/24/21 16:10:00
> [2021-05-24 15:13:45] DEBUG [UIW7kChYQ38] C: EHLO [127.0.0.1]
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 250-DDBH-PLESK-WEB1.webhostbox.net [191.8.39.16], this server offers 5 extensions
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 250-AUTH NTLM CRAM-MD5 LOGIN
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 250-SIZE 31457280
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 250-HELP
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 250-AUTH=LOGIN
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 250 STARTTLS
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] C: STARTTLS
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 220 Ready to start TLS
> [2021-05-24 15:13:46] INFO  [UIW7kChYQ38] Connection upgraded with STARTTLS
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] C: EHLO [127.0.0.1]
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 250-DDBH-PLESK-WEB1.webhostbox.net [191.8.39.16], this server offers 4 extensions
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 250-AUTH NTLM CRAM-MD5 LOGIN
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 250-SIZE 31457280
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 250-HELP
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] S: 250 AUTH=LOGIN
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] SMTP handshake finished
> [2021-05-24 15:13:46] DEBUG [UIW7kChYQ38] C: AUTH LOGIN
> [2021-05-24 15:13:47] DEBUG [UIW7kChYQ38] S: 334 VXNlcm5hbWU6
> [2021-05-24 15:13:47] DEBUG [UIW7kChYQ38] C: aG9zdG1hc3RlckBkb3R0Lm5ldC5icg==
> [2021-05-24 15:13:47] DEBUG [UIW7kChYQ38] S: 334 UGFzc3dvcmQ6
> [2021-05-24 15:13:47] DEBUG [UIW7kChYQ38] C: RmVpamFvIzIwMjEj
> [2021-05-24 15:13:47] DEBUG [UIW7kChYQ38] S: 235 Authenticated
> [2021-05-24 15:13:47] INFO  [UIW7kChYQ38] User "hostmaster@MyDomain.net.br" authenticated
> [2021-05-24 15:13:47] INFO  Sending message <5a7dad46-613b-f68a-2291-c1509f055fe3@MyDomain.net.br> to <MyEmail@gmail.com>
> [2021-05-24 15:13:47] DEBUG [UIW7kChYQ38] C: MAIL FROM:<hostmaster@MyDomain.net.br>
> [2021-05-24 15:13:47] DEBUG [UIW7kChYQ38] S: 250 Requested mail action okay, completed
> [2021-05-24 15:13:47] DEBUG [UIW7kChYQ38] C: RCPT TO:<MyEmail@gmail.com>
> [2021-05-24 15:13:47] DEBUG [UIW7kChYQ38] S: 250 Requested mail action okay, completed
> [2021-05-24 15:13:47] DEBUG [UIW7kChYQ38] C: DATA
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] S: 354 Start mail input; end with <CRLF>.<CRLF>
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Content-Type: multipart/alternative;
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38]  boundary="--_NmP-3f53e24e3829f202-Part_1"
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] From: hostmaster@MyDomain.net.br
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] To: MyEmail@gmail.com
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Reply-To: hostmaster@MyDomain.net.br
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Subject: Strapi test mail to: MyEmail@gmail.com
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Message-ID: <5a7dad46-613b-f68a-2291-c1509f055fe3@MyDomain.net.br>
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Date: Mon, 24 May 2021 15:13:45 +0000
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] MIME-Version: 1.0
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38]
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] ----_NmP-3f53e24e3829f202-Part_1
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Content-Type: text/plain; charset=utf-8
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Content-Transfer-Encoding: quoted-printable
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38]
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Great! You have correctly configured the Strapi email plugin with the =
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] nodemailer provider.=20
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] For documentation on how to use the email plugin checkout: https://strapi.=
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] io/documentation/developer-docs/latest/development/plugins/email.=
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] html
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] ----_NmP-3f53e24e3829f202-Part_1
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Content-Type: text/html; charset=utf-8
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Content-Transfer-Encoding: quoted-printable
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38]
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Great! You have correctly configured the Strapi email plugin with the =
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] nodemailer provider.=20
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] For documentation on how to use the email plugin checkout: https://strapi.=
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] io/documentation/developer-docs/latest/development/plugins/email.=
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] html
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] ----_NmP-3f53e24e3829f202-Part_1--
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] .
> [2021-05-24 15:13:48] INFO  [UIW7kChYQ38] <1130 bytes encoded mime message (source size 1127 bytes)>
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] S: 250 Requested mail action okay, completed
> [2021-05-24 15:13:48] DEBUG [UIW7kChYQ38] Closing connection to the server using "end"
> [2021-05-24T15:13:48.419Z] debug POST /email/test (4022 ms) 200
> [2021-05-24 15:13:48] INFO  [UIW7kChYQ38] Connection closed

Trying to use the costumer’s E-mail Account (WITHOUT SUCCESS)

> plugin.js
> ----------------------------------------
>   email: {
>       provider: 'nodemailer',
>       providerOptions: {
>         host: env('EMAIL_HOST','mail.CostumerDomain.com.br'),
>         port: env('EMAIL_PORT',465), 
>         connectionTimeout: 90000, 
>         secure: true, 
>         debug: true, 
>         logger: true, 
>         dkim: {
>           domainName: "CostumerDomain.com.br",
>           keySelector: "default",
>           privateKey: "-----BEGIN RSA PRIVATE KEY-----\nTheCompletPrivateKey\n-----END RSA PRIVATE KEY-----"
>         }, 
>         auth: {
>           user: env('EMAIL_USER','CustomerAccount@CostumerDomain.com.br'),
>           pass: env('EMAIL_PASS','CustomerPassword')
>         },
>         tls: {
>           rejectUnauthorized: true
>         }
>       }, 
>       settings: {
>         defaultFrom: env('SENDMAIL_DEFAULT_FROM','CustomerAccount@CostumerDomain.com.br'),
>         defaultReplyTo: env('SENDMAIL_DEFAULT_REPLY_TO','CustomerAccount@CostumerDomain.com.br'),
>         testAddress: env('SENDMAIL_DEFAULT_TEST_ADDRESS','MyAccount@gmail.com') //Attempted hostmaster@MyDomain.net.br too
>       }
>   }
> 
> The NodeMailer LOG
> ----------------------------------------
> [2021-05-24 14:43:54] DEBUG Sending mail using SMTP/6.6.0[client:6.6.0]
> [2021-05-24 14:43:55] DEBUG [lkgUbpFv4Q4] Resolved mail.CostumerDomain.com.br as 192.185.217.29 [cache miss]
> [2021-05-24 14:43:55] INFO  [lkgUbpFv4Q4] Secure connection established to 192.185.217.29:465
> [2021-05-24 14:43:56] DEBUG [lkgUbpFv4Q4] S: 220-br240.hostgator.com.br ESMTP Exim 4.94.2 #2 Mon, 24 May 2021 11:43:57 -0300 
> [2021-05-24 14:43:56] DEBUG [lkgUbpFv4Q4] S: 220-We do not authorize the use of this system to transport unsolicited, 
> [2021-05-24 14:43:56] DEBUG [lkgUbpFv4Q4] S: 220 and/or bulk e-mail.
> [2021-05-24 14:43:56] DEBUG [lkgUbpFv4Q4] C: EHLO [127.0.0.1]
> [2021-05-24 14:43:57] DEBUG [lkgUbpFv4Q4] S: 250-br240.hostgator.com.br Hello [127.0.0.1] [191.8.39.16]
> [2021-05-24 14:43:57] DEBUG [lkgUbpFv4Q4] S: 250-SIZE 52428800
> [2021-05-24 14:43:57] DEBUG [lkgUbpFv4Q4] S: 250-8BITMIME
> [2021-05-24 14:43:57] DEBUG [lkgUbpFv4Q4] S: 250-PIPELINING
> [2021-05-24 14:43:57] DEBUG [lkgUbpFv4Q4] S: 250-PIPE_CONNECT
> [2021-05-24 14:43:57] DEBUG [lkgUbpFv4Q4] S: 250-AUTH PLAIN LOGIN
> [2021-05-24 14:43:57] DEBUG [lkgUbpFv4Q4] S: 250 HELP
> [2021-05-24 14:43:57] DEBUG [lkgUbpFv4Q4] SMTP handshake finished
> [2021-05-24 14:43:57] DEBUG [lkgUbpFv4Q4] C: AUTH PLAIN AGFtd0BlbWhhcC5jb20uYnIARW0jMjBAMjEjQXA=
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] S: 235 Authentication succeeded
> [2021-05-24 14:43:58] INFO  [lkgUbpFv4Q4] User "CustomerAccount@CostumerDomain.com.br" authenticated
> [2021-05-24 14:43:58] INFO  Sending message <2a50a43a-f138-83e3-94c6-a9d5987a1531@CostumerDomain.com.br> to <MyAccount@gmail.com>
> [2021-05-24 14:43:58] DEBUG Signing outgoing message with 1 keys
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] C: MAIL FROM:<CustomerAccount@CostumerDomain.com.br>
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] S: 250 OK
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] C: RCPT TO:<MyAccount@gmail.com>
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] S: 250 Accepted
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] C: DATA
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] S: 354 Enter message, ending with "." on a line by itself
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CostumerDomain.com.br;
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4]  q=dns/txt; s=default; bh=9rP2hllQcRkp/ehK7a7cTPxHxmdR2NtfYHN3YsYtKHs=;
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4]  h=from:reply-to:subject:date:message-id:to:mime-version:content-type;
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4]  b=cwer4mpW50m0IDLK2GmfKa/100JMAvyFq8ejhLyfyfuyloKngZ6DQ18EAkCJewiW/lUWEbQYV
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4]  PSi2bsKG4ZfHYjDYq1Gs9s5zv0XdL/ciVKFBlkdQoV5pUw9vKHNiuBJ7rqGmTMH/b4LZYhtLNxB
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4]  wWq0lAFri39J0s9jjSkelvds0dl89p2wo/2yfTpXn2ExwFiVf1djMHO57rd4zPJKRfTfds0655O
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4]  dM7ZFlFJPO8sGwOrnlgyd7lVMaP63Ca9A5KjghZI0FlbOliaplp2uelnyFi52fAR801aDkDIQVg
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4]  y2YpTsP8nLcIyqTz20TKo+rFoO+n0xlE6Vs3onIjYvSg==
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Content-Type: multipart/alternative;
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4]  boundary="--_NmP-7ba133eba0466312-Part_1"
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] From: CustomerAccount@CostumerDomain.com.br
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] To: MyAccount@gmail.com
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Reply-To: CustomerAccount@CostumerDomain.com.br
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Subject: Strapi test mail to: MyAccount@gmail.com
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Message-ID: <2a50a43a-f138-83e3-94c6-a9d5987a1531@CostumerDomain.com.br>
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Date: Mon, 24 May 2021 14:43:54 +0000
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] MIME-Version: 1.0
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4]
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] ----_NmP-7ba133eba0466312-Part_1
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Content-Type: text/plain; charset=utf-8
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Content-Transfer-Encoding: quoted-printable
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4]
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Great! You have correctly configured the Strapi email plugin with the =
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] nodemailer provider.=20
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] For documentation on how to use the email plugin checkout: https://strapi.=
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] io/documentation/developer-docs/latest/development/plugins/email.=
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] html
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] ----_NmP-7ba133eba0466312-Part_1
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Content-Type: text/html; charset=utf-8
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Content-Transfer-Encoding: quoted-printable
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4]
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Great! You have correctly configured the Strapi email plugin with the =
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] nodemailer provider.=20
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] For documentation on how to use the email plugin checkout: https://strapi.=
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] io/documentation/developer-docs/latest/development/plugins/email.=
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] html
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] ----_NmP-7ba133eba0466312-Part_1--
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] .
> [2021-05-24 14:43:58] INFO  [lkgUbpFv4Q4] <1696 bytes encoded mime message (source size 1693 bytes)>
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] S: 250 OK id=1llBoF-001FgK-3t
> [2021-05-24 14:43:58] DEBUG [lkgUbpFv4Q4] Closing connection to the server using "end"
> [2021-05-24T14:43:58.897Z] debug POST /email/test (4519 ms) 200
> [2021-05-24 14:43:59] INFO  [lkgUbpFv4Q4] Connection closed

Did you check if the cert was actually valid (the whole chain)

Have you tried port 587, 465 is very rarely used anymore unless it’s a really legacy host :thinking:

Hi @DMehaffy thanks for your reply.

I tried all the combinations, but I will check again.
The certificate was obtained directly from HostGator’s CPanel.

This is the configuration provided by HostGator

Thanks !

After conducting tests with 06 different email accounts and domains, hosted by different providers:
03 inside Brazil: Hostgator, Locaweb and UolHost
03 outside Brazil: 01 ResellerClub and 02 on AWS LightSail

The solution is: GET OUT OF BRAZILIAN PROVIDERS

Result:
Inside Brazil 0 x Outside Brazil 3

It is a sad reality that had to be proven with a few hours of work.
It remains to propose to client to change provider or request an upgrade on the HostGator server (just a dream).

Thanks @DMehaffy for his last words!

No problem :slight_smile: Email has been around for a longggggggggggg time and many providers are just extremely legacy and don’t want to upgrade their infrastructure.

Hi BeanSampa… im having a similar issue but i cant find the way you show the nodemailer log

im using strapi v.3.6.0
mongo
node v14

and the error i get is Error: can not connect to any SMTP server

Hi Fernando_Moreno, sorry for the delay.

STRAPI: 3.6.8
Node: 12.20.2
NPM: 7.24.0
PM2 5.1.0

My plugins.js
ConfigNodeMailer_1

Can I get information from NodeMailer by running PM2 LOG

any news? I’m also facing issues with nodemailer and strapi

STRAPI: 3.6.8

email: {
    config: {
      provider: 'nodemailer',
      providerOptions: {
        host: env('SMTP_HOST', 'smtp....),
        port: env('SMTP_PORT', 587),
        auth: {
          user: env('SMTP_USERNAME'),
          pass: env('SMTP_PASSWORD'),
        },
      },
      settings: {
        defaultFrom: "no-reply@email.com.br",
        defaultReplyTo: "no-reply@email.com.br",
      },
    },
  },
module.exports = {
  sendMail: async (ctx) => {
    try {
      const body = ctx.request.body;
      await strapi.plugins["email-designer"].services.email.sendTemplatedEmail(
        {
          to: body.email,
          from: 'no-reply@email.com.br'
        },
        {
          templateId: 1,
        },
        {
          body
        }
      );
      return { status: "success" };
    } catch (err) {
      ctx.response.status = 404
      return { error: err }
    }
  }
};

response

{
	"error": {
		"errno": -111,
		"code": "ESOCKET",
		"syscall": "connect",
		"address": "127.0.0.1",
		"port": 1025,
		"command": "CONN"
	}
}