在节点中发送电子邮件方面没有那么丰富的经验,正如我所看到的,有不同的选项可供选择。在以下场景中使用哪个选项?
将 nodemailer 与 sendgrid 结合使用:
正如我所看到的,我必须添加额外的包"nodemailer-sendgrid-transport"
迫使他们一起工作。
Because var transporter = nodemailer.createTransport({ service: 'SendGrid', auth: {...});
行不通的。 (总是返回错误的用户名/密码)
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: ['[email protected] /cdn-cgi/l/email-protection', '[email protected] /cdn-cgi/l/email-protection'],
from: '[email protected] /cdn-cgi/l/email-protection',
subject: 'Hi there',
text: 'Awesome sauce',
html: '<b>Awesome sauce</b>'
};
client.sendMail(email, function(err, info) { ... });
仅使用 sendgrid 模块而不使用 nodemailer 包:
var sendgrid = require('sendgrid')('blabla', 'blabla');
var email = {
to: ['[email protected] /cdn-cgi/l/email-protection', '[email protected] /cdn-cgi/l/email-protection'],
from: '[email protected] /cdn-cgi/l/email-protection',
subject: 'Hi there',
text: 'Awesome sauce',
html: '<b>Awesome sauce</b>'
};
sendgrid.send(email, function(err, json) { ... });
因此,在第二个示例中,我将仅包含一个包(sengrid),而在第一种方法中,我必须包含两个包(nodemailer 和 nodemailer-sendgrid-transport)。我发现第一种方法比第二种方法更抽象,因为我可以更新或完全切换到其他一些服务传输(例如 gmail),或者我可以吗?但另一方面,我不认为在不同的运输对象之间进行切换是合适的。
所有这一切的附带问题是如何将模板与此解决方案一起使用。我在官方指南中没有看到任何有关模板的内容,也没有在以下位置看到:https://github.com/sendgrid/sendgrid-nodejs https://github.com/sendgrid/sendgrid-nodejs也不在:https://github.com/andris9/Nodemailer https://github.com/andris9/Nodemailer:
电子邮件模板与此完全不同,我需要安装新的软件包来处理它?
最后我觉得我提出了一个非常弱智的问题。