NodeMailer queuing outgoing email, but email never sends











up vote
5
down vote

favorite
1












I'm trying to send an email from my own domain without using an external SMTP server. I'm using NodeMailer's SMTP connection:



let options = {
secure: true,
port: consts.portOut,//465
host: consts.host, //mydomain.com
transactionLog: true,
debug: true,
requireTLS: true,
authMethod: 'PLAIN',
};

let connection = new SMTPConnection(options);

connection.connect(function() {
let auth = {
user: 'abc',
pass: 'def'
};

connection.login(auth, function(err) {
if (err) {
console.log("Authentication failed!", err);
}
console.log("Authentication to SMTP server successful.");

let envelope = {
from: 'fee@mydomain.com',
to: 'myemail@gmail.com'
};

let message = 'message hello world';

connection.send(envelope, message, function(err, info) {
if (err) {
console.log("err:::", err);
} else {
console.log('info?', info);
//connection.quit();
}
});

connection.quit();

});

});

connection.on("error", function(err) {
console.log(err);
});


My server code using NodeMailer's SMTP Server:



const options = {
secure: true,
size: 25000000, //25MB
authMethods: ['PLAIN'],
key: hskey,
cert: hscert,
ca: [hschain],
onAuth(auth, session, callback) {
if(auth.username !== 'abc' || auth.password !== 'def') {
return callback(new Error('Invalid username or password'));
}
callback(null, {user: 123}); // where 123 is the user id or similar property
},
onConnect(session, callback) {
console.log("the address is:", session.remoteAddress)
if (session.remoteAddress === consts.ip) {
return callback(); // Accept the address
} else {
return callback(new Error('Only connections from %s allowed', consts.ip));
}

},
onData(stream, session, callback) {
simpleParser(stream, (err, parsed) => {
if(err) {
console.error(err);
} else {
console.log(parsed);
}

});
stream.on('end', function () {
let err;
if(stream.sizeExceeded){
err = new Error('Message exceeds fixed maximum message size');
err.responseCode = 552;
return callback(err);
}
callback(null, 'Message queued as abcdef');
});
}

};

const emailServer = new SMTPServer(options);

emailServer.listen(consts.portOut, function () {
processSMTPConnection(consts, hskey);
});

emailServer.on("error", function (err) {
console.error("Error %s", err.message);
});


So after my client connects to my local SMTP server, the last message I get is 'Message queued as abcdef' and nothing ever sends (nothing ever arrives in my gmail inbox or any other email testing services)...



No incorrect ports are blocked, so I must be missing something(?).
Is this not how to correctly use NodeMailer?
Should I be able to send emails from my local domain using NodeMailer?










share|improve this question
























  • What is console.log(parsed) supposed to do? I get an uncaught SyntaxError when I run it in a repl.
    – mykeels
    Nov 29 at 9:48










  • @mykeels thanks for taking a look. it prints out the email stream from my SMTP connection file which encludes what you see in envelope and message above
    – orangeMint
    Nov 29 at 13:25










  • @mykeels the backslash shouldn't be there and isn't in my actual code, it must have slipped in when I was cleaning things up to post on SO
    – orangeMint
    Nov 29 at 13:56















up vote
5
down vote

favorite
1












I'm trying to send an email from my own domain without using an external SMTP server. I'm using NodeMailer's SMTP connection:



let options = {
secure: true,
port: consts.portOut,//465
host: consts.host, //mydomain.com
transactionLog: true,
debug: true,
requireTLS: true,
authMethod: 'PLAIN',
};

let connection = new SMTPConnection(options);

connection.connect(function() {
let auth = {
user: 'abc',
pass: 'def'
};

connection.login(auth, function(err) {
if (err) {
console.log("Authentication failed!", err);
}
console.log("Authentication to SMTP server successful.");

let envelope = {
from: 'fee@mydomain.com',
to: 'myemail@gmail.com'
};

let message = 'message hello world';

connection.send(envelope, message, function(err, info) {
if (err) {
console.log("err:::", err);
} else {
console.log('info?', info);
//connection.quit();
}
});

connection.quit();

});

});

connection.on("error", function(err) {
console.log(err);
});


My server code using NodeMailer's SMTP Server:



const options = {
secure: true,
size: 25000000, //25MB
authMethods: ['PLAIN'],
key: hskey,
cert: hscert,
ca: [hschain],
onAuth(auth, session, callback) {
if(auth.username !== 'abc' || auth.password !== 'def') {
return callback(new Error('Invalid username or password'));
}
callback(null, {user: 123}); // where 123 is the user id or similar property
},
onConnect(session, callback) {
console.log("the address is:", session.remoteAddress)
if (session.remoteAddress === consts.ip) {
return callback(); // Accept the address
} else {
return callback(new Error('Only connections from %s allowed', consts.ip));
}

},
onData(stream, session, callback) {
simpleParser(stream, (err, parsed) => {
if(err) {
console.error(err);
} else {
console.log(parsed);
}

});
stream.on('end', function () {
let err;
if(stream.sizeExceeded){
err = new Error('Message exceeds fixed maximum message size');
err.responseCode = 552;
return callback(err);
}
callback(null, 'Message queued as abcdef');
});
}

};

const emailServer = new SMTPServer(options);

emailServer.listen(consts.portOut, function () {
processSMTPConnection(consts, hskey);
});

emailServer.on("error", function (err) {
console.error("Error %s", err.message);
});


So after my client connects to my local SMTP server, the last message I get is 'Message queued as abcdef' and nothing ever sends (nothing ever arrives in my gmail inbox or any other email testing services)...



No incorrect ports are blocked, so I must be missing something(?).
Is this not how to correctly use NodeMailer?
Should I be able to send emails from my local domain using NodeMailer?










share|improve this question
























  • What is console.log(parsed) supposed to do? I get an uncaught SyntaxError when I run it in a repl.
    – mykeels
    Nov 29 at 9:48










  • @mykeels thanks for taking a look. it prints out the email stream from my SMTP connection file which encludes what you see in envelope and message above
    – orangeMint
    Nov 29 at 13:25










  • @mykeels the backslash shouldn't be there and isn't in my actual code, it must have slipped in when I was cleaning things up to post on SO
    – orangeMint
    Nov 29 at 13:56













up vote
5
down vote

favorite
1









up vote
5
down vote

favorite
1






1





I'm trying to send an email from my own domain without using an external SMTP server. I'm using NodeMailer's SMTP connection:



let options = {
secure: true,
port: consts.portOut,//465
host: consts.host, //mydomain.com
transactionLog: true,
debug: true,
requireTLS: true,
authMethod: 'PLAIN',
};

let connection = new SMTPConnection(options);

connection.connect(function() {
let auth = {
user: 'abc',
pass: 'def'
};

connection.login(auth, function(err) {
if (err) {
console.log("Authentication failed!", err);
}
console.log("Authentication to SMTP server successful.");

let envelope = {
from: 'fee@mydomain.com',
to: 'myemail@gmail.com'
};

let message = 'message hello world';

connection.send(envelope, message, function(err, info) {
if (err) {
console.log("err:::", err);
} else {
console.log('info?', info);
//connection.quit();
}
});

connection.quit();

});

});

connection.on("error", function(err) {
console.log(err);
});


My server code using NodeMailer's SMTP Server:



const options = {
secure: true,
size: 25000000, //25MB
authMethods: ['PLAIN'],
key: hskey,
cert: hscert,
ca: [hschain],
onAuth(auth, session, callback) {
if(auth.username !== 'abc' || auth.password !== 'def') {
return callback(new Error('Invalid username or password'));
}
callback(null, {user: 123}); // where 123 is the user id or similar property
},
onConnect(session, callback) {
console.log("the address is:", session.remoteAddress)
if (session.remoteAddress === consts.ip) {
return callback(); // Accept the address
} else {
return callback(new Error('Only connections from %s allowed', consts.ip));
}

},
onData(stream, session, callback) {
simpleParser(stream, (err, parsed) => {
if(err) {
console.error(err);
} else {
console.log(parsed);
}

});
stream.on('end', function () {
let err;
if(stream.sizeExceeded){
err = new Error('Message exceeds fixed maximum message size');
err.responseCode = 552;
return callback(err);
}
callback(null, 'Message queued as abcdef');
});
}

};

const emailServer = new SMTPServer(options);

emailServer.listen(consts.portOut, function () {
processSMTPConnection(consts, hskey);
});

emailServer.on("error", function (err) {
console.error("Error %s", err.message);
});


So after my client connects to my local SMTP server, the last message I get is 'Message queued as abcdef' and nothing ever sends (nothing ever arrives in my gmail inbox or any other email testing services)...



No incorrect ports are blocked, so I must be missing something(?).
Is this not how to correctly use NodeMailer?
Should I be able to send emails from my local domain using NodeMailer?










share|improve this question















I'm trying to send an email from my own domain without using an external SMTP server. I'm using NodeMailer's SMTP connection:



let options = {
secure: true,
port: consts.portOut,//465
host: consts.host, //mydomain.com
transactionLog: true,
debug: true,
requireTLS: true,
authMethod: 'PLAIN',
};

let connection = new SMTPConnection(options);

connection.connect(function() {
let auth = {
user: 'abc',
pass: 'def'
};

connection.login(auth, function(err) {
if (err) {
console.log("Authentication failed!", err);
}
console.log("Authentication to SMTP server successful.");

let envelope = {
from: 'fee@mydomain.com',
to: 'myemail@gmail.com'
};

let message = 'message hello world';

connection.send(envelope, message, function(err, info) {
if (err) {
console.log("err:::", err);
} else {
console.log('info?', info);
//connection.quit();
}
});

connection.quit();

});

});

connection.on("error", function(err) {
console.log(err);
});


My server code using NodeMailer's SMTP Server:



const options = {
secure: true,
size: 25000000, //25MB
authMethods: ['PLAIN'],
key: hskey,
cert: hscert,
ca: [hschain],
onAuth(auth, session, callback) {
if(auth.username !== 'abc' || auth.password !== 'def') {
return callback(new Error('Invalid username or password'));
}
callback(null, {user: 123}); // where 123 is the user id or similar property
},
onConnect(session, callback) {
console.log("the address is:", session.remoteAddress)
if (session.remoteAddress === consts.ip) {
return callback(); // Accept the address
} else {
return callback(new Error('Only connections from %s allowed', consts.ip));
}

},
onData(stream, session, callback) {
simpleParser(stream, (err, parsed) => {
if(err) {
console.error(err);
} else {
console.log(parsed);
}

});
stream.on('end', function () {
let err;
if(stream.sizeExceeded){
err = new Error('Message exceeds fixed maximum message size');
err.responseCode = 552;
return callback(err);
}
callback(null, 'Message queued as abcdef');
});
}

};

const emailServer = new SMTPServer(options);

emailServer.listen(consts.portOut, function () {
processSMTPConnection(consts, hskey);
});

emailServer.on("error", function (err) {
console.error("Error %s", err.message);
});


So after my client connects to my local SMTP server, the last message I get is 'Message queued as abcdef' and nothing ever sends (nothing ever arrives in my gmail inbox or any other email testing services)...



No incorrect ports are blocked, so I must be missing something(?).
Is this not how to correctly use NodeMailer?
Should I be able to send emails from my local domain using NodeMailer?







email smtp sendmail smtpclient nodemailer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 14 hours ago

























asked Nov 19 at 14:32









orangeMint

771324




771324












  • What is console.log(parsed) supposed to do? I get an uncaught SyntaxError when I run it in a repl.
    – mykeels
    Nov 29 at 9:48










  • @mykeels thanks for taking a look. it prints out the email stream from my SMTP connection file which encludes what you see in envelope and message above
    – orangeMint
    Nov 29 at 13:25










  • @mykeels the backslash shouldn't be there and isn't in my actual code, it must have slipped in when I was cleaning things up to post on SO
    – orangeMint
    Nov 29 at 13:56


















  • What is console.log(parsed) supposed to do? I get an uncaught SyntaxError when I run it in a repl.
    – mykeels
    Nov 29 at 9:48










  • @mykeels thanks for taking a look. it prints out the email stream from my SMTP connection file which encludes what you see in envelope and message above
    – orangeMint
    Nov 29 at 13:25










  • @mykeels the backslash shouldn't be there and isn't in my actual code, it must have slipped in when I was cleaning things up to post on SO
    – orangeMint
    Nov 29 at 13:56
















What is console.log(parsed) supposed to do? I get an uncaught SyntaxError when I run it in a repl.
– mykeels
Nov 29 at 9:48




What is console.log(parsed) supposed to do? I get an uncaught SyntaxError when I run it in a repl.
– mykeels
Nov 29 at 9:48












@mykeels thanks for taking a look. it prints out the email stream from my SMTP connection file which encludes what you see in envelope and message above
– orangeMint
Nov 29 at 13:25




@mykeels thanks for taking a look. it prints out the email stream from my SMTP connection file which encludes what you see in envelope and message above
– orangeMint
Nov 29 at 13:25












@mykeels the backslash shouldn't be there and isn't in my actual code, it must have slipped in when I was cleaning things up to post on SO
– orangeMint
Nov 29 at 13:56




@mykeels the backslash shouldn't be there and isn't in my actual code, it must have slipped in when I was cleaning things up to post on SO
– orangeMint
Nov 29 at 13:56












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Documentation here has a note that states:




This module does not make any email deliveries by itself. smtp-server
allows you to listen on ports 25/24/465/587 etc. using SMTP or LMTP
protocol and that’s it. Your own application is responsible of
accepting and delivering the message to destination.




(emphasis mine)



Your server seems to accept the email (that's why it's showing that the message has been queued) but it doesn't delivers to destination.



To expand a little bit on how to send the message once it arrives to your SMTP server. If the TO address is local, just put the message in their mailbox. But if you want to "remail" the message, you need to contact the TO mail exchange with the message.



Something like:



const toExchange = getMX(parsed.to);
const outMessage = createMessageFromParsed(parsed);

const transporter = createTransport({
port: 25,
host: toExchange,
name: os.hostname(),
});

transporter.sendMail(outMessage);





share|improve this answer























  • Hmm interesting, you are correct it does accept messages both from my client and other email servers. If NodeMailer doesn't send mail, what service out there does?
    – orangeMint
    12 hours ago










  • nodemailer can send the message. See createTransport (nodemailer.com/usage).
    – joksnet
    12 hours ago










  • Well, I feel dumb, but you're a lifesaver, thanks man!
    – orangeMint
    11 hours ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376807%2fnodemailer-queuing-outgoing-email-but-email-never-sends%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Documentation here has a note that states:




This module does not make any email deliveries by itself. smtp-server
allows you to listen on ports 25/24/465/587 etc. using SMTP or LMTP
protocol and that’s it. Your own application is responsible of
accepting and delivering the message to destination.




(emphasis mine)



Your server seems to accept the email (that's why it's showing that the message has been queued) but it doesn't delivers to destination.



To expand a little bit on how to send the message once it arrives to your SMTP server. If the TO address is local, just put the message in their mailbox. But if you want to "remail" the message, you need to contact the TO mail exchange with the message.



Something like:



const toExchange = getMX(parsed.to);
const outMessage = createMessageFromParsed(parsed);

const transporter = createTransport({
port: 25,
host: toExchange,
name: os.hostname(),
});

transporter.sendMail(outMessage);





share|improve this answer























  • Hmm interesting, you are correct it does accept messages both from my client and other email servers. If NodeMailer doesn't send mail, what service out there does?
    – orangeMint
    12 hours ago










  • nodemailer can send the message. See createTransport (nodemailer.com/usage).
    – joksnet
    12 hours ago










  • Well, I feel dumb, but you're a lifesaver, thanks man!
    – orangeMint
    11 hours ago















up vote
1
down vote



accepted










Documentation here has a note that states:




This module does not make any email deliveries by itself. smtp-server
allows you to listen on ports 25/24/465/587 etc. using SMTP or LMTP
protocol and that’s it. Your own application is responsible of
accepting and delivering the message to destination.




(emphasis mine)



Your server seems to accept the email (that's why it's showing that the message has been queued) but it doesn't delivers to destination.



To expand a little bit on how to send the message once it arrives to your SMTP server. If the TO address is local, just put the message in their mailbox. But if you want to "remail" the message, you need to contact the TO mail exchange with the message.



Something like:



const toExchange = getMX(parsed.to);
const outMessage = createMessageFromParsed(parsed);

const transporter = createTransport({
port: 25,
host: toExchange,
name: os.hostname(),
});

transporter.sendMail(outMessage);





share|improve this answer























  • Hmm interesting, you are correct it does accept messages both from my client and other email servers. If NodeMailer doesn't send mail, what service out there does?
    – orangeMint
    12 hours ago










  • nodemailer can send the message. See createTransport (nodemailer.com/usage).
    – joksnet
    12 hours ago










  • Well, I feel dumb, but you're a lifesaver, thanks man!
    – orangeMint
    11 hours ago













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Documentation here has a note that states:




This module does not make any email deliveries by itself. smtp-server
allows you to listen on ports 25/24/465/587 etc. using SMTP or LMTP
protocol and that’s it. Your own application is responsible of
accepting and delivering the message to destination.




(emphasis mine)



Your server seems to accept the email (that's why it's showing that the message has been queued) but it doesn't delivers to destination.



To expand a little bit on how to send the message once it arrives to your SMTP server. If the TO address is local, just put the message in their mailbox. But if you want to "remail" the message, you need to contact the TO mail exchange with the message.



Something like:



const toExchange = getMX(parsed.to);
const outMessage = createMessageFromParsed(parsed);

const transporter = createTransport({
port: 25,
host: toExchange,
name: os.hostname(),
});

transporter.sendMail(outMessage);





share|improve this answer














Documentation here has a note that states:




This module does not make any email deliveries by itself. smtp-server
allows you to listen on ports 25/24/465/587 etc. using SMTP or LMTP
protocol and that’s it. Your own application is responsible of
accepting and delivering the message to destination.




(emphasis mine)



Your server seems to accept the email (that's why it's showing that the message has been queued) but it doesn't delivers to destination.



To expand a little bit on how to send the message once it arrives to your SMTP server. If the TO address is local, just put the message in their mailbox. But if you want to "remail" the message, you need to contact the TO mail exchange with the message.



Something like:



const toExchange = getMX(parsed.to);
const outMessage = createMessageFromParsed(parsed);

const transporter = createTransport({
port: 25,
host: toExchange,
name: os.hostname(),
});

transporter.sendMail(outMessage);






share|improve this answer














share|improve this answer



share|improve this answer








edited 12 hours ago

























answered 12 hours ago









joksnet

2,0851118




2,0851118












  • Hmm interesting, you are correct it does accept messages both from my client and other email servers. If NodeMailer doesn't send mail, what service out there does?
    – orangeMint
    12 hours ago










  • nodemailer can send the message. See createTransport (nodemailer.com/usage).
    – joksnet
    12 hours ago










  • Well, I feel dumb, but you're a lifesaver, thanks man!
    – orangeMint
    11 hours ago


















  • Hmm interesting, you are correct it does accept messages both from my client and other email servers. If NodeMailer doesn't send mail, what service out there does?
    – orangeMint
    12 hours ago










  • nodemailer can send the message. See createTransport (nodemailer.com/usage).
    – joksnet
    12 hours ago










  • Well, I feel dumb, but you're a lifesaver, thanks man!
    – orangeMint
    11 hours ago
















Hmm interesting, you are correct it does accept messages both from my client and other email servers. If NodeMailer doesn't send mail, what service out there does?
– orangeMint
12 hours ago




Hmm interesting, you are correct it does accept messages both from my client and other email servers. If NodeMailer doesn't send mail, what service out there does?
– orangeMint
12 hours ago












nodemailer can send the message. See createTransport (nodemailer.com/usage).
– joksnet
12 hours ago




nodemailer can send the message. See createTransport (nodemailer.com/usage).
– joksnet
12 hours ago












Well, I feel dumb, but you're a lifesaver, thanks man!
– orangeMint
11 hours ago




Well, I feel dumb, but you're a lifesaver, thanks man!
– orangeMint
11 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376807%2fnodemailer-queuing-outgoing-email-but-email-never-sends%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'