When trying to send email within Node using Nodemailer (https://github.com/nodemailer/nodemailer), the call to the sendMail
of the Nodemailer transporter is raising the error Greeting never received
when using in conjunction with an Ethereal test email account.
I have tried using both a «callback approach» and also an «async/await» approach, but the same error is thrown in both scenarios. Both examples are pretty much straight from the working examples in the Nodemailer documentation. Maybe I’m missing something simple?
Here is the «callback approach» code that is producing the error:
it('can send email with a dynamic test account', done => {
nodemailer.createTestAccount((err, account) => {
const transporter = nodemailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
auth: {
user: account.user, // generated ethereal user
pass: account.pass // generated ethereal password
}
});
const mailOptions = {
from: '"Fred Foo 👻" <foo@example.com>', // sender address
to: 'bar@example.com, baz@example.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world?', // plain text body
html: '<b>Hello world?</b>' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
done();
});
});
}).timeout(10000);
And here is the stacktrace of the error:
{ Error: Greeting never received
at SMTPConnection._formatError (/Users/<username>/projects/personal/learning-tests/javascript/nodemailer/node_modules/nodemailer/lib/smtp-connection/index.js:606:19)
at SMTPConnection._onError (/Users/<username>/projects/personal/learning-tests/javascript/nodemailer/node_modules/nodemailer/lib/smtp-connection/index.js:579:20)
at Timeout._greetingTimeout.setTimeout (/Users/<username>/projects/personal/learning-tests/javascript/nodemailer/node_modules/nodemailer/lib/smtp-connection/index.js:520:22)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5) code: 'ETIMEDOUT', command: 'CONN' }
And some additional info:
- node version:
8.11.2
- nodemailer version:
4.6.4
- operating system:
OSX version 10.12.6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Closed
JYC-99 opened this issue
May 31, 2015
· 8 comments
Closed
» Error: Greeting never received» problem
#441
JYC-99 opened this issue
May 31, 2015
· 8 comments
Comments
The version:
«nodemailer»: «^1.3.4»,
I just tried several different mail service but always have this issue. I turn ssl authentication on, the code is like:
or
I do not know what is the problem
Just experienced this as well.
Fixed using secureConnection: true
and port: 465
.
wuranxu reacted with laugh emoji
I also encountered this problem,do not know what is the problem too. 😢
This usually happens when the server expects encrypted connection but you start out as plaintext. To connect to secure servers you should use the following setup (note the secure
option):
var transporter = nodemailer.createTransport({ host: 'localhost', port: 465, secure: true, auth: { user: 'username', pass: 'password' } });
This was referenced
May 12, 2016
ixdi
mentioned this issue
Apr 19, 2017
petrus-v
pushed a commit
to petrus-v/docs-1
that referenced
this issue
Mar 21, 2019
ErisDS
pushed a commit
to TryGhost/docs
that referenced
this issue
Apr 1, 2019
Just experienced this as well.
Fixed usingsecureConnection: true
andport: 465
.
This solved it for me
I tried this and yet getting Error: connect ECONNREFUSED 127.0.0.1:465
Just experienced this as well. Fixed using
secureConnection: true
andport: 465
.
I used secureConnection: true
and it worked for me. Thanks.
Hey guys fairly new to this subreddit, but anyways I am in the process of attempting to build a contact form that will send an email to my email. So far I have been able to send the form data from my client (svelte) to my server (sapper), but an issue is arising whenever I attempt to configure my nodemailer transport. I figured I would see if a fresh set of eyes could take a look at it. Thanks in advance!
contact.js (separate file that is server side)
import nodemailer from "nodemailer";
import dotenv from "dotenv";
dotenv.config();
const { EMAIL_USER, EMAIL_PASS } = process.env;
let transport = nodemailer.createTransport({
host: "imap.gmail.com",
port: 993,
auth: {
user: EMAIL_USER,
pass: EMAIL_PASS,
}
});
// After inspecting my code I believe that the error is coming from this code block
====================================================================================transport.verify((error, success) => {
if (error) {
console.log(error);
} else {
console.log("Time to receive some emails!");
};
});
====================================================================================
export async function post(req, res, next) {
res.setHeader('Content-Type', 'application/json');
let data = req.body;
let mailOptions = {
from: `${data.name} <${data.email}>`,
to: "",
subject: "The Suggestion Box",
html: `Hello Chris,<br><br>${data.suggestion}<br><br><br>Sincerely,<br><br>${data.name}`,
};
transport.sendMail(mailOptions, (err, data) => {
if (err) {
res.json({msg: "fail" });
} else {
res.json({ msg: "success" });
};
});
return res.end(JSON.stringify({ success: true }));
};
However, whenever I run this code it seems to give me this error message.
Error: Greeting never received
at SMTPConnection._formatError (E:ProgrammingWeb DevelopmentTTRPGnode_modulesnodemailerlibsmtp-connectionindex.js:784:19)
at SMTPConnection._onError (E:ProgrammingWeb DevelopmentTTRPGnode_modulesnodemailerlibsmtp-connectionindex.js:770:20)
at Timeout.<anonymous> (E:ProgrammingWeb DevelopmentTTRPGnode_modulesnodemailerlibsmtp-connectionindex.js:704:22)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
code: 'ETIMEDOUT',
command: 'CONN'
}
Thanks in advance guys!
562
July 04, 2017, at 00:46 AM
whenever i run the code I’m getting the error » Error: Greeting never received at SMTPConnection._formatError….»
function automatedMailSender(req,res){
var mailOptions = {
from: "abc <abc@test.com>", // sender address
to: 'nit@test.com', // list of receivers
subject: 'Hello ', // Subject line
text: 'Hello world ?', // plain text body
html: '<b>Hello world ?</b>' // html body
};
var mailer=nodemailer.createTransport({
host: 'mail.test.com',
port: 465,
secure: false, // secure:true for port 465, secure:false for port 587
auth: {
user: 'mymail@test.com',
pass: '1234'
}
});
mailer.sendMail(mailOptions, (error, response)=>{
if(error){
console.log('mail not sent n',error);
}
else{
console.log("Message sent: " ,response.message);
}
});
}
I’m I doing something wrong in the code.Please help
Answer 1
Try something like that, it work perfectly for me:
//Create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport(
'smtps://USERNAME%40gmail.com:PASSWORD@smtp.gmail.com');
// setup e-mail data with unicode symbols
var mailOptions = {
from: '"Michel®
Answer 2
If you are using Gmail to send mails then try this.
Allow less secure apps to connect to Gmail.
- sending Mail
- mail with
- with nodemailer
-
05:30
Trying to take the file extension out of my URL
-
04:00
display list that in each row 1 li
-
00:00
Read audio channel data from video file nodejs
-
10:30
session not saved after running on the browser
-
9:10
Best way to trigger worker_thread OOM exception in Node.js
-
07:40
Firebase Cloud Functions: PubSub, "res.on is not a function"
-
04:00
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
-
9:20
AWS XRAY on Fargate service
-
7:40
How to resolve getting Error 429 Imgur Api
jQuery Categories
Highcharts tooltip stacking points
Using forEach to iterate an array, add to object and use the forEach index for the object key doesn’t work
How to update the specific user’s data in two tables from sql using php [on hold]
allow users to add many pictures to the same poste array with one upload file buttun.if impossible what would be the solution
READ ALSO
SyntaxError: Unexpected token function
Making a chat application referencing via Node in action, and upon running the serverjs, got the following error: function serveStatic(response,cache,absPath) ^^^^^^^^ SyntaxError: Unexpected token function at Object
705
Many-to-many with graphql-relay not working
I am using Graphql Relay for applying connection modelI have scenario as teacher and student are having Many-to-Many relationship
321
How to install React Js with CodeIgniter..?
Possible duplicates:
377
How to keep my web services awake in nodejs to run forever though i am using forever npm module?
I am using rabbitmq,mongodb and mysql with my webservicesTo keep my webservices awake i am using npm forever module(forever start app
356
I am running a Node server on Heroku to support a mobile app. When users submit a feedback form in the app, a POST request goes to <myapp>.herokuapp.com/feedback
, with the feedback message.
I would like to use Nodemailer to send myself an email when the form is submitted. However, I get the following error instead:
{ Error: Greeting never received
at SMTPConnection._formatError (/app/node_modules/smtp-connection/lib/smtp-connection.js:528:15)
at SMTPConnection._onError (/app/node_modules/smtp-connection/lib/smtp-connection.js:514:16)
at SMTPConnection.<anonymous> (/app/node_modules/smtp-connection/lib/smtp-connection.js:455:18)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5) code: 'ETIMEDOUT', command: 'CONN' }
Here is the full code for my /feedback
endpoint:
const nodemailer = require('nodemailer')
const smtpTransport = require('nodemailer-smtp-transport')
const validateEmail = require('../util').validateEmail
const config = {
host: 'securemail.webnames.ca',
port: 587,
secure: false, // secure:true for port 465, secure:false for port 587
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
}
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport(smtpTransport(config))
// This is the endpoint callback:
module.exports = function feedback(req, res) {
// setup email data with unicode symbols
let mailOptions = {
// from: `"${userName}" <${userEmail}>`,
from: 'hello@<myapp>.com',
to: 'hello@<myapp>.com',
subject: 'Feedback',
text: req.body.message,
html: req.body.message,
}
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
res.setHeader('Content-Type', 'application/json')
res.send({ success: false, error })
return console.error(error)
}
console.log('Message %s sent: %s', info.messageId, info.response)
res.setHeader('Content-Type', 'application/json')
res.send({ success: true })
})
}
I am using a generic email host to send emails (webnames.ca). Emails sent with a desktop mail client go through fine.
Any ideas?
via Bogdan Balan