Node - options for sending email, sendgrid and nodemailer, one of them or combined

Not as experienced with sending email to node, and as I see it, there are different choices. Which option to use in the following scenario?

Using node -mailer with sengrid:
As I see it, I have to add an extra package "nodemailer-sendgrid-transport" to make them work together.
Because var transporter = nodemailer.createTransport({ service: 'SendGrid', auth: {...}); will not work. (Always returns an invalid username / password)

 var nodemailer = require('nodemailer'), sendGridTransport = require('nodemailer-sendgrid-transport'); var options = { auth: { api_user: 'blabla', api_key: 'blabla' } }; var client = nodemailer.createTransport(sendGridTransport(options)); var email = { to: [' joe@foo.com ', ' mike@bar.com '], from: ' roger@tacos.com ', subject: 'Hi there', text: 'Awesome sauce', html: '<b>Awesome sauce</b>' }; client.sendMail(email, function(err, info) { ... }); 

Using only the sendgrid module without the nodemailer package:

 var sendgrid = require('sendgrid')('blabla', 'blabla'); var email = { to: [' joe@foo.com ', ' mike@bar.com '], from: ' roger@tacos.com ', subject: 'Hi there', text: 'Awesome sauce', html: '<b>Awesome sauce</b>' }; sendgrid.send(email, function(err, json) { ... }); 

So, in the second example, I will include only one package (sengrid), with the first approach I have to include two packages (nodemailer and nodemailer-sendgrid-transport). I see that the first approach is a big abstraction in a second, because I can upgrade or completely switch to some other service transport (for example, gmail) or can I? But in another case, I do not see a situation where it would be advisable to switch between different transport objects.

Side question: all this is how to use templates with these solutions. I do not see anything about templates in the official manuals and not on: https://github.com/sendgrid/sendgrid-nodejs and not on: https://github.com/andris9/Nodemailer :

Email templates is a completely different story, and do I need to install a new package that will work with it?
In the end, I feel that I have a very difficult question.

+2
source share
1 answer

I used nodemailer with Mandrill without any problems.

This is the code that works in my case, but you do not mention it:

 // Create a SMTP transport object var transport = nodemailer.createTransport("SMTP", { service: mainConfigFile.smtpServer.service, // use well known service auth: { user: mainConfigFile.smtpServer.user, pass: mainConfigFile.smtpServer.pass } }); 

Note that the credentials are stored in mainConfigFile, but it is clear what the intent is.

I think you'll be fine with the nodemiler.

Can you provide more information about the error received?

+2
source

Source: https://habr.com/ru/post/983347/


All Articles