I have a web server which is implemented using NodeJs. Now I want to add a functionality which will send a group of people email alerts if an event occurs. But I do not know how to add this feature in the existing code. I researched online and found sendgrid-nodejs but I do not know if that would work or not. I am not sure how to start. Please help.
You might want to check out nodemailer module.
The website has many different examples which you can follow.
Here is a one of those examples:
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport();
transporter.sendMail({
from: 'sender#address',
to: 'receiver#address',
subject: 'hello',
text: 'hello world!'
});
Related
I am doing on my website a reset of password, and i would like to send an email to the user who is asking this reset. I looked few packages like nodemailer and sendmail. The problem with nodemailer, i don't want to give my email in the code, even if i'm the only who is seeing this. The problem with sendmail is:
error on connectMx Error: can not connect to any SMTP server
code sendmail :
const sendmail = require('sendmail')();
sendmail({
from: 'test#test.com',
to: 'adz#gmail.com',
subject: 'Hello',
html: 'test mail '
}, function (err, reply) {
console.log(err && err.stack)
console.dir(reply)
}),
When i was working only php, there was a function called "mail", it didn't need an account gmail, hotmail ... So i'm asking to you, is there a way to don't give my account to nodemailer or not please, or is there an other way to send mails with nodeJS ?
Thanks a lot and i hope i have been clear about my problem (sorry for the bad english).
I am a bit confused about nodemailer as a simple standard solution for node JS mailing.
I see the current nodemailer ver 3.x.x costs over $800(?!?!) and since I am building a module in an my MVP, to send an email once in a while, seems to me that I need another solution.
so:
how do I setup an older nodemailer version (I guess pre version 3.x.x)?
Any examples of how to use the older version code?
Other working options? I tried "mailover" with gmail and gmail rejects it will alerting on "Less secure app... because it has known security problems or is out of date..." issue.
Thanks in advance.
You can use this command to install the old nodemailer version
npm install nodemailer#2.0.0 --save
Then start to code by importing nodemailer module
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport();
transporter.sendMail({
from: 'sender#address',
to: 'receiver#address',
subject: 'hello',
html: '<b>hello world!</b>'
text: 'hello world!'
});
I am trying to make a small dashboard where i can send bulk email using my own SMTP servers. I want to use node for this, can anyone guide from where to start i want to send mails from different SMTP servers.
A most common way to send email in Node is using Nodemailer. It has an excellent documentation.
You can use it to send email using any SMTP servers and there are a lot of preconfigured ways to send using Gmail or other specialized transports.
The available transports are - from the README:
nodemailer-mailgun-transport for sending messages through Mailgun's Web API
nodemailer-mandrill-transport for sending messages through Mandrill's Web API
nodemailer-pickup-transport for storing messages to pickup folders
nodemailer-sailthru-transport for sending messages through Sailthru's Web API
nodemailer-sendgrid-transport for sending messages through SendGrid's Web API
nodemailer-sendmail-transport for piping messages to the sendmail command
nodemailer-ses-transport for sending messages to AWS SES
nodemailer-sparkpost-transport for sending messages through SparkPost's Web API
nodemailer-stub-transport is just for returning messages, most probably for testing purposes
nodemailer-wellknown for sending messages through one of those many supported services
nodemailer-postmark-transport for sending messages through Postmark's Web API
add yours (see transport api documentation here)
Here is a simple usage example in the Nodemailer GitHub repo
var nodemailer = require('nodemailer');
// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport('smtps://user%40gmail.com:pass#smtp.gmail.com');
// setup e-mail data with unicode symbols
var mailOptions = {
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
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
See:
https://nodemailer.com/
https://github.com/nodemailer/nodemailer
For bulk mailing it's much better to use a service like Mailgun or Mandrill because doing bulk mailing yourself using SMTP it's a lot of hassle to make sure that your emails are going through spam filters and that you are not blacklisted for sending too much email, that you don't exceed any limits of your ISP etc. Sending emails is more complicated than people usually think and with prices like $0.0001 per email in Mailgun it's also dirt cheap.
all. In my nodejs-sails app i'm need to send very big amount of email notifications (>1kk in month) fast. What most efficient and cheap way of doing this? I'm not know very good how all this mailing stuff work, so please show me the way for further googling.
Do i'm need to rent smtp server, use software like Haraka or anything else? Or maybe i need to use Amazon SES?
Thank for your answers.
Yes the most efficient way is going to be a third party email service.
As Jeff Atwood (co-founder of SO) puts it "Email sucks;"
http://blog.codinghorror.com/so-youd-like-to-send-some-email-through-code/
As an example, I use Mandrill's SMTP service over Nodemailer:
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'Mandrill',
auth: {
user: process.env.MANDRILL_USER,
pass: process.env.MANDRILL_API_KEY
}
});
transporter.sendMail({
from: 'sender#address',
to: 'receiver#address',
subject: 'hello',
text: 'hello world!'
});
Nodemailer supports all sorts of transports and services out of the box. Docs here: https://github.com/andris9/Nodemailer
I tried to use nodemailer to send emails using my gmail account.
However, Google rejects my login as suspicious and thinks I am a hacker.
I tried Yahoo which does send the email.
My questions are:
1) How can I configure nodemailer to send emails thru gmail
2) Standard/Reliable email library in node.js community with good support that can be used in production.
I was recently playing around with this as well, and the error I received from Google was simply stating that I needed to create an application specific password. Try following the instructions here.
As for your second question, I do not know of any reasons as to why nodemailer can't be used in production.
I used emailjs, and haven't had that issue. Not sure if that's because it's email.js or because it's Google Apps vs Gmail, or maybe Google is just less suspicious with this app for some reason. Maybe useful to try to triangulate:
$> npm install emailjs
emailjs = require('emailjs');
...
var server = emailjs.server.connect({
user:"myname#mygoogleapp.com",
password:"Secret#!1",
host:"smtp.gmail.com",
ssl:true
});
server.send({
text: message
from:"Display name <return#mydomain.com>",
to:email,
subject:"Subject"
},
function (err, message) { ... }