I am trying to send emails via nodemailer without SMTP transport. So i\'ve done that:
var mail = require(\"nodemailer\").mail;
mail({
from: \"Fred Foo ✔ <
From your example output it seems to connecting to wrong port 25, gmail smtp ports which are opened are 465 for SSL and the other 587 TLS.
Nodemailer detects the correct configuration based on the email domain, in your example you have not set the transporter object so it uses the default port 25 configured. To change the port specify in options the type.
Here's the small example that should work with gmail:
var nodemailer = require('nodemailer');
// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP", {
service: 'Gmail',
auth: {
user: "test.nodemailer@gmail.com",
pass: "Nodemailer123"
}
});
console.log('SMTP Configured');
// Message object
var message = {
// sender info
from: 'Sender Name <sender@example.com>',
// Comma separated list of recipients
to: '"Receiver Name" <nodemailer@disposebox.com>',
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔',
// plaintext body
text: 'Hello to myself!',
// HTML body
html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/></p>'
};
console.log('Sending Mail');
transport.sendMail(message, function(error){
if(error){
console.log('Error occured');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
// if you don't want to use this transport object anymore, uncomment following line
//transport.close(); // close the connection pool
});
You need to have a SMTP server, an email server which forwards the emails on your behalf. So either set up your own SMTP server like Haraka or provide credentials to Nodemailer to connect to one e.g. Gmail,MSN,Yahoo. Even I have started learning NodeJs and was trying to include an emailing feature in my project and this was the same problem I faced.
probably it is windows firewall or antivirus preventing outgoing access. try to enable nodemailer debug messages.
Enabling debug
var nodemailer = require("nodemailer"),
transport = nodemailer.createTransport('direct', {
debug: true, //this!!!
});
transport.sendMail({
from: "Fred Foo ✔ <foo@blurdybloop.com>", // sender address
to: "******@gmail.com", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world ✔", // plaintext body
html: "<b>Hello world ✔</b>" // html body
}, console.error);
when you on your setting , it allows to send mails. https://www.google.com/settings/security/lesssecureapps this one worked for me
use nodemailer 0.7.1.
if you previously installed nodemailer then remove it by
npm remove nodemailer
now install it by
npm install nodemailer@0.7.1
the following code send mail without login, but it will work only in production environment, it won't work locally
var mail = require("nodemailer").mail;
mail({
from: "Fred Foo ✔ <foo@blurdybloop.com>", // sender address
to: "bar@blurdybloop.com, baz@blurdybloop.com", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world ✔", // plaintext body
html: "<b>Hello world ✔</b>" // html body
});
This appears to be possible in nodemailer. Not sure if this wasn't around when the other answers were provided. As documented here: https://nodemailer.com/transports/sendmail/ you can you use the built in sendmail if available to do your sending. I've tested this for my own use and works fine. There are obviously advantages of SMTP but to say it's not possible is not true.