Node.js nodemailer error - wrong version number/invalid greeting - node.js

I have a big problem with setting up the nodemailer on my node.js server. Tried everthing I found on the internet but nothing works. The only thing that was easy to setup was the gmail service. but unfortunately I cannot use that one.
With secure set to true, i get an ssl error with the reason wrong version code.
[Error: 22468:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:
] {
library: 'SSL routines',
function: 'ssl3_get_record',
reason: 'wrong version number',
code: 'ESOCKET',
command: 'CONN'
}
But when I try to set secure to false, then I get an invalid greeting error.
Error: Invalid greeting. response=* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2016 Double Precision, Inc. See COPYING for distribution information.: * OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2016 Double Precision, Inc. See COPYING for distribution information.
at SMTPConnection._actionGreeting (C:\Users\Motiondata\Documents\repos\rmn_app\server\rmn_server\node_modules\nodemailer\lib\smtp-connection\index.js:1189:27)
at SMTPConnection._processResponse (C:\Users\Motiondata\Documents\repos\rmn_app\server\rmn_server\node_modules\nodemailer\lib\smtp-connection\index.js:932:20)
at SMTPConnection._onData (C:\Users\Motiondata\Documents\repos\rmn_app\server\rmn_server\node_modules\nodemailer\lib\smtp-connection\index.js:739:14)
at Socket.SMTPConnection._onSocketData (C:\Users\Motiondata\Documents\repos\rmn_app\server\rmn_server\node_modules\nodemailer\lib\smtp-connection\index.js:189:44)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:284:9)
at Socket.Readable.push (_stream_readable.js:223:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
code: 'EPROTOCOL',
response: '* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2016 Double Precision, Inc. See COPYING for distribution information.',
command: 'CONN'
}
My code is the following:
const transporter = nodemailer.createTransport({
host: process.env.MAIL_HOST, // mx.example.com
port: process.env.MAIL_PORT, // 143
secure: true,
auth: {
user: process.env.MAIL_ADDRESS,
pass: process.env.MAIL_PWD
}
})
I checked the credentials a thousand time, they are definetly not the problem.
Hope anyone can help me.
Thanks in advance.

Refering to this issue mentioned here: https://github.com/andris9/Nodemailer/issues/165
See if this helps, adding the tls.ciphers option to use SSLv3:
const transport = nodemailer.createTransport({
host: process.env.MAIL_HOST, // mx.example.com
port: process.env.MAIL_PORT, // 143
secureConnection: false, // TLS requires secureConnection to be false
auth: {
user: process.env.MAIL_ADDRESS,
pass: process.env.MAIL_PWD
},
tls: {
ciphers:'SSLv3'
}
});
For Outlook365, this should work:
service: "Outlook365",
auth: {
user: '[YOUR_O365_EMAIL]',
pass: '[YOUR_O365_PASSWORD]'
},
Refer here: https://stackoverflow.com/a/37725123/9360885
If you're using HotMail, then remove host and port, and just add service: "hotmail".

use
secure: false, // true for 465, false for other ports
Example from nodemailer docs:
let transporter = nodemailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: account.user, // generated ethereal user
pass: account.pass // generated ethereal password
}
});
source: nodemailer examples

I used port 465 with Gmail and that worked. Got the "wrong version number" error with 587. Example below is for a GCP service account in a Cloud Function.
const transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
type: "OAuth2",
user: process.env.GMAIL_ADDRESS,
serviceClient: process.env.CLIENT_ID,
privateKey: process.env.PRIVATE_KEY.replace(/\\n/g, "\n"),
},
});

I also ran in this problem. But I managed to fix it.
It's quite simple to solve.
Solution:
port: process.env.MAIL_PORT * 1
This will change your process.env.MAIL_PORT type from a string to integer.
Why there was an error?
NodeMail require a port with a type of integer, but you were passing a string. So that caused an error.

If you are still receiving the issue, fix by inputting this into your browser manually while logged in.
https://accounts.google.com/DisplayUnlockCaptcha

change smtp port 587 to 465
smtp:{
name:"noreply#gmail.com",
host:process.env.SMTP_HOST,
secure: true,//true
port: 465,//465
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
}, // here it goes
},

Related

Using Webmail with Nodemailer

I used gmail with node mailer to create a login system in js node.
In development mode I used gmail.
const sendEmail = async options =>{
//1)Create a transporter
// const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL_SEND_SESSION,
pass: process.env.EMAIL_SEND_PASSWORD,
}
});
//2) Define the mail options
const mailOptions = {
from:'Creative Point <test764#gmail.com>',
to:options.email,
subject:options.subject,
html:options.message
}
//3) Actually send the email
await transporter.sendMail(mailOptions);
};
But in production mode I would like to use webmail,I received when I created the data and port account on cpanel.
const transporter = nodemailer.createTransport({
service:'smtp.specialsoft.ro ',
port: 465,
auth: {
user: process.env.EMAIL_SEND_SESSIONCPANEL,
pass: process.env.EMAIL_SEND_PASSWORDCPANEL,
}
});
But it gives me the next mistake.
Error: There was an error sending the email.Try again later!Error: Invalid login: 535-5.7.8 Username
and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials g20sm3266545ejz.88 - gsmtp
at C:\Users\Cosmin\Desktop\Authentification System Node
JS,Express,JsonWebToken\controllers\sessionController.js:56:21
at processTicksAndRejections (internal/process/task_queues.js:93:5)
I haven't found anything relevant on the internet about this error.
I solved the problem by following the steps below.
I installed a module: nodemailer-smtp-transport.
const smtpTransport = require('nodemailer-smtp-transport');
I corrected the host name and some options.
host:'mail.mydomani.ro'
secureConnection: false,
tls: {
rejectUnauthorized: false
}
3)I integrated the module nodemailer-smtp-transport in the transporter.
const transporter = nodemailer.createTransport(smtpTransport({
host:'mail.mydomanin.ro',
secureConnection: false,
tls: {
rejectUnauthorized: false
},
port: 587,
auth: {
user: process.env.EMAIL_SEND_SESSION,
pass: process.env.EMAIL_SEND_PASSWORD,
}
}));

Nodemailer send mail using gmail account showing response code 534-5.7.14

// create reusable transporter object using the default SMTP transport
transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: 'yourEmail',
pass: 'yourPassword'
}
});
{ [Error: Invalid login] code: 'EAUTH', response: '534-5.7.14
Please log in via your web browser and\n534-5.7.14 then try
again.\n534-5.7.14 Learn more at n534 5.7.14
https://support.google.com/mail/answer/78754 77sm13524842wml.20 - g
smtp', responseCode: 534 }
You may need to "Allow Less Secure Apps" in your Gmail account (it's all the way at the bottom). You also may need to "Allow access to your Google account".
var transporter = nodemailer.createTransport(smtpTransport({
host: config.email_config.SMTP_HOST,
port: config.email_config.SMTP_PORT,
tls: {
rejectUnauthorized: false
},
auth: {
user: config.email_config.SMTP_AUTH_USER,
pass: config.email_config.SMTP_AUTH_PASS
}
}));
use like thiss....

Error 535 while setting up nodemailer with GoDaddy

I'm wondering if anyone has figured out how to use GoDaddy hosted email with nodemailer. I have an email submission box from my contact form, and it triggers the following script:
function sendEmail ( to, subject, body ) {
var transporter = nodemailer.createTransport({
service: 'Godaddy',
host: "relay-hosting.secureserver.net",
port: 465,
secureConnection: true,
auth: {
user: 'email#godaddydomain.com',
pass: 'password'
}
});
var mailOptions = {
from: 'email#godaddydomain.com',
to: to,
subject: subject,
text: body
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
}
I've tried a few different options, and made sure my ports are all open, but I'm having a hard time with the authentication. I keep getting errors like this:
{ Error: Invalid login: 535 Authentication Failed for email#godaddydomain.com. User does not have any relays assigned.
at SMTPConnection._formatError (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:577:19)
at SMTPConnection._actionAUTHComplete (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:1306:34)
at SMTPConnection._responseActions.push.str (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:349:26)
at SMTPConnection._processResponse (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:733:20)
at SMTPConnection._onData (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:529:14)
at Socket._socket.on.chunk (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:481:47)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20)
code: 'EAUTH',
response: '535 Authentication Failed for email#godaddydomain.com. User does not have any relays assigned.',
responseCode: 535,
command: 'AUTH PLAIN' }
Any thoughts or suggestions would be really appreciated.
It seems like this error is related to the hostname. Try this one:
var transporter2 = nodemailer.createTransport({
service: 'Godaddy',
host: "smtpout.secureserver.net",
secureConnection: true,
port: 465
})
I was facing the same error. I changed configuration to the following:
var transporter = nodemailer.createTransport({
host: "smtpout.secureserver.net",
secure: true,
secureConnection: false, // TLS requires secureConnection to be false
tls: {
ciphers: "SSLv3",
},
requireTLS: true,
port: 465,
debug: true,
auth: {
user: "xxxx#yyyy.com",
pass: "pass",
},
});
It worked like a charm for me.
In case anyone's still looking for this (as I have been the last few days!), I found all the server information GoDaddy was suggesting was completely wrong. Found the answer in cPanel - if you go to the main bit, and click on 'Email Accounts', on your account it should have an option on the right saying 'Connect Devices'. Click on that and it'll give you the correct server and port information for what you need, which for me ended up being this:
var transporter = nodemailer.createTransport({
host: "sxb1plzcpnl487525.prod.sxb1.secureserver.net",
secure: true,
secureConnection: true,
port: 465,
auth: {user: "yourcpanelusername#yourdomain.com", pass: "yourcpanelpassword"},
tls: {rejectUnauthorized: false}
});
Took me forever to find that specific weird server it needed. Hope this helps. Apologies for formatting, it's my first post here but I wanted to help as I've spent days on this now.

nodemailer and zoho email issue '530 Must issue a STARTTLS command first.'

I am using the latest version of nodemailer version 4.1.0. I tried using the sample code available here
https://nodemailer.com/smtp/
Here is my code
let transporter = nodemailer.createTransport({
host: 'smtp.zoho.com',
port:587,
secure: false,
auth: {
user: this.user,
pass: this.password
}
});
var mailOptions: nodemailer.SendMailOptions = {
from: ****#***.com,
to: test#abc.com,
subject: 'Hello ✔',
text: 'Hello world ✔',
html: '<b>Hello world ✔</b>'
};
transporter
.sendMail(mailOptions)
.then(
(info) => {
// console.log(info);
resolve({status: info.messageId})
}
)
.catch(err => {
// console.log(err);
reject({status: err.toString()})
})
I get the following error. I have set the secure flag as false, and have also used ignodeTLS. The previous version of nodemailer 0.7.1 did not have any issues. Am I missing out on any specific configuration?
{ Error: Invalid login: 530 Must issue a STARTTLS command first.
at SMTPConnection._formatError
(C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:577:19)
at SMTPConnection._actionAUTHComplete (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:1306:34)
at SMTPConnection._responseActions.push.str (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:349:26)
at SMTPConnection._processResponse (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:733:20)
at SMTPConnection._onData (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:529:14)
at Socket._socket.on.chunk (C:\Project\NotificationService\node_modules\nodemailer\lib\smtp-connection\index.js:481:47)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:548:20)
code: 'EAUTH',
response: '530 Must issue a STARTTLS command first.',
responseCode: 530,
command: 'AUTH PLAIN' }
you can also use this without these tls parameter default value is false.
you got the error because of you don't pass service:'zoho' in nodemailer
let transporter = nodemailer.createTransport({
service:'Zoho',
host: this.service,
port:587,
secure: false,
auth: {
user: this.user,
pass: this.password
}
});
After going through the typings( "#types/nodemailer") file I added the following flags
1) service :'Zoho'
2) requireTLS :false
it is working now :)
let transporter = nodemailer.createTransport({
service:'Zoho',
host: this.service,
port:587,
secure: false,
ignoreTLS:true,
requireTLS:false,
auth: {
user: this.user,
pass: this.password
}
});
In the year 2022, I got this on the official documentation https://nodemailer.com/smtp/well-known/
let transporter = nodemailer.createTransport({
service: 'SendPulse', // no need to set host or port etc.
auth: {
user: 'account.email#example.com',
pass: 'smtp-password'
}
});
transporter.sendMail(...)
So, for Zoho just simply:
let transporter = nodemailer.createTransport({
service: 'Zoho', // no need to set host or port etc.
auth: {
user: 'account.email#example.com',
pass: 'smtp-password'
}
});
transporter.sendMail(...)
Just test it and works. I believe it doesn't need to put any setting if we use "Well-known services"
Hope this helps someone drop by in this thread :).

Error sending email using nodemailer via Office365 smtp (MEANjs scaffold)

I'm trying to use Office365 SMTP to send email using Nodemailer (in a MEANjs scaffold), but I get the following error:
[Error: 140735277183760:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:795:]
I'm using the following Nodemailer options:
{
host: 'smtp.office365.com',
port: '587',
auth: { user: 'xxxx', pass: 'xxxx' },
secure: 'false',
tls: { ciphers: 'SSLv3' }
}
Removing the tls field doesn't make a difference. What am I missing?
The solution was simple. The 'secure' field should be 'secureConnection'. The MEANjs scaffold that generated the configs created mailer options with the 'secure' field. The rest of the options are fine. For anyone that needs a working Office365 SMTP nodemailer options block, the following should work:
{
host: 'smtp.office365.com',
port: '587',
auth: { user: 'xxxx', pass: 'xxxx' },
secureConnection: false,
tls: { ciphers: 'SSLv3' }
}
I know this is old but if anyone looks this up in 2019, you can just add
service: "Outlook365"
and you won't have to specify connection options.
Node Mailer Docs
let transporter = nodemailer.createTransport({
service: "Outlook365",
auth: {
user: 'FROMUSER#office365.com',
pass: 'FROMUSERPASS'
},
})
let info = transporter.sendMail({
from: 'FROMUSER#office365.com',
to: 'TOUSER#office365.com',
subject: 'Test',
text: 'hello world',
html: '<h1>TEST</h1>'
})
This nodemailer documentation https://nodemailer.com/2-0-0-beta/setup-smtp/ indeed states options.secure and not options.secureConnection. It also suggests, in an example, that options.secure is expecting a boolean value true or false and not a string value 'true' or 'false'. Removing the '' from around 'false' works for me.
My problem was that the username and password were spelled correctly but I did not login in the Account after creation. So I used a mail program (Thunderbird) to login once and had to change my password and then I had access over Nodemailer.

Resources