How to send very big amount of email notifications with sails app? - node.js

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

Related

SMTP server using hmailserver. Host cannot be resolved to a type

I am trying to create a local SMTP server. I configured everything according to this: Link to set-up hmailserver
After that, I ran my diagnostics thing and it said host(in my case, noreply#bufferoverflow.com) cannot be resolved. I googled and read the documentation and question section of hmailserver Docs and found that I am missing a DNS configuration on my machine.
I followed this article to set-up the DNS ip to name: How to add ip domain mapping in windows
127.0.0.1 bufferoverflow.com
on my
C:\Windows\System32\drivers\etc>notepad hosts.ics
It still said host cannot be resolved to a type. I tried to see if the port was actually open and listening. So I did this command in CMD:
netstat -a
It's listening. I doubled checked everything but coudn't found where I was going wrong. I created a simple nodejs server and hosted it on port 80 at localhost and typed "bufferoverflow.com" in my browser it opened 127.0.0.1 aka localhost which is because it has an ip domain mapping I have given.
Now I am lost as why the hostname can't be resolved. My DNS is cool. Everthing is configured as docs says and the port is also open and listening. Please help me.
So based on what you said you created your own SMTP server which is nice and all to learn, but I would recommend using SendinBlue 3rd party service FREE and gives you 300 mails/day
Getting Started with sendinblue:
Link: https://www.sendinblue.com/
Go make and an account free of charge till you decide to pay you'll read there
Once your account is all set, and activated often SMTP service for ones account is not automatically activate so you'd have to email them and they literally respond within 24hr I LOVE THE SERVICE(I am not promoting nor sponsored to hype them or anything just saying the truth of what I have experienced).
So now at this point your account and SMTP service is activated, now question is how do you use sendinBlue?
In your dashboard on your Top right you will see your username
Click on that and a dropdown menu should appear
Then you want to go to SMTP & API
Once you then you will see a menu with API Keys on the left and SMTP on the right
You want to click on the SMTP.
Once you the you will see Login that would be the email you registered with and you will see Master password now that is what you use to authenticate yourself.
Implementation: Now you have everything sorted you know where you keys are and login
In .env file
sendinBlue__login=<Your email that your saw in that smtp tab>
sendinBlue__key= <Key you saw in that smtp tab>
In your file where you want to send email
const nodemailer = require('nodemailer');
router.post('/api/email', (request, response)=>{
const transporter = nodemailer.createTransport({
service:'SendinBlue',
auth:{
user:process.env.sendinBlue__login,
pass:process.env.sendinBlue__key
}
})
const mailOptions = {
from:process.env.sendinBlue__login
to:'example#gmail.com',
subject:'Order confirmation',
html:`
<h1>Confirmation of your received order</h1>
`
}
transporter.sendMail(mailOptions, (error, info)=>{
if (error){
console.log(error);
return response.status(500).json({msg:"Email failed to send probably network problems or SMTP not activated"});
}
return reponse.status(200).json({msg:'Email sent'});
})
})
Now this is how easy sendinBlue works just simple signup and account activation also SMTP activation if not activated from get go by email customer support
If that guide above did not make sense to you: Shameless plug
You can go checkout my video that I did and I was using sendinBlue with nodemailer for emailing it's a bit at the end
Link: https://youtu.be/5vWXbGIdDQw
Now If you want to send an email using noreply#domain.com with sendinBlue you do not even have to have the email activated but still can send
How you go about this is the way you craft your mailOptions
router.get("/api/test", (request, response) => {
const transpoter = nodemailer.createTransport({
service: "SendinBlue",
auth: {
user: process.env.sendinBlue__email,
pass: process.env.sendinBlue__key,
},
});
const mailOptions = {
from: "noreply#Test.com",
to: "juniorWebProjects#gmail.com",
subject: "Confirmation Order",
html: `
<h1>Order Received</h1>
`,
};
transpoter.sendMail(mailOptions, (err, info) => {
if (err) {
return console.log(err);
}
return console.log("Message sent");
});
});
See on my mailOptions I explicitly wrote myself the email that I want and when sendinBlue sends that email the receiver will see that is coming from noreply#Test.com

Google Security Alert With Node Mailer

I am having an issue with my portfolio site, which is currently coded using Node and Express. I am using Nodemailer with Google's SMTP for my contact form. My code is all working, my problem is actually with Google.
Sometimes the emails from my contact form will go through no problem. Other times, people will get an error because Google will send me a "Critical Security Alert" for my connected account (thus not allowing the SMTP to log in). I have already enabled less secure apps. I have searched for hours for an answer and cannot find one anywhere.
This is what my createTransport() function looks like (I have changed the email and password):
const smtpTrans = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: "example#gmail.com",
pass: "example"
}
})
Anyone know how I can fix this?
You need to log in your Google account and then go to https://myaccount.google.com/lesssecureapps. In that web you should set the switch to ON (should be OFF the first time you enter) so that it allows other applications to access your account

Unlock a nodejs program through email answer

I'm working with dialog flow on Google home, and I have a program which sends an email (via Nodemailer), I would like to lock a function, and unlock it depending on the email's answer.
Maybe I could put a link inside the email as "if you agree with this, click on this link, otherwise don't".
Can I get the answer with my program? If yes, how?
Here is the function I use to send my email:
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '**********',
pass: '**********'
}
});
var mailOptions = {
from: '*********#gmail.com',
to: '********.********#gmail.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
Thanks.
You have a lot of things you need to think about when designing this - nevermind actually coding it.
Somehow you need to get the user's address in the first place. Google Home (and the Actions on Google platform) don't have a way to give this to you, and asking the user for their info is a bad UX.
One way you can get their address is through Account Linking, which lets you link their Assistant account to an account in your system. This won't give you the address directly, but since they have to log in through your website first, you can either use Google Login (and thus get their profile info) or ask them for it as part of your account process.
Once you have their address - you want to verify it. There are a ton of suggestions on the web about how to correctly do double-opt-in. Make sure you follow them. There are node modules that will help you do this as well - you don't need to write your own.
Coding this securely is not something to be taken lightly. Doing it wrong lets you become a spam relay. Doing it not-quite-right may just have you considered as spam by the email providers.
All you have to do is Define System so that from that E-mail box e-mail will be sent. Example, you can add your Gmail account and password. Add this code just in Server.js just below the var app=express() line.
var smtpTransport = nodemailer.createTransport({
service: "gmail",
host: "smtp.gmail.com",
auth: {
user: "",
pass: ""
}
});

Bulk email sending usiing node.js

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.

How to add an email library in an existing nodejs server

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!'
});

Resources