节点-用于发送电子邮件,sendgrid和nodemailer之一或组合的选项 [英] Node - options for sending email, sendgrid and nodemailer one of them or combined

查看:115
本文介绍了节点-用于发送电子邮件,sendgrid和nodemailer之一或组合的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在节点上发送电子邮件的经验不足,我可以看到有不同的选项可供选择。在以下情况下使用哪个选项?

Not so experienced with sending email in node and as i can see there are different option to choose among. Which option to use in following scenario?

将节点邮件程序与sengrid配合使用:

如我所见,我必须添加其他程序包 nodemailer-sendgrid-transport 强制它们一起工作。
因为 var transporter = nodemailer.createTransport({服务:'SendGrid',auth:{...}); 不起作用。 (始终返回错误的用户名/密码)

Using node-mailer with sengrid:
As i can see i must add additional package "nodemailer-sendgrid-transport" to force them to work together.
Because var transporter = nodemailer.createTransport({ service: 'SendGrid', auth: {...}); won't work. (Always returning Bad 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) { ... });

仅使用不带nodemailer软件包的sendgrid模块:

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) { ... });

因此,在第二个示例中,我将仅包含一个包(sengrid),在第一种方法中,我必须包含两个软件包(nodemailer和nodemailer-sendgrid-transport)。我看到第一种方法比第二种方法更大,因为我可以更新或完全切换到其他服务传输(例如gmail),还是可以?但是从另一方面来说,我看不到在不同的传输对象之间进行切换的合适情况。

So with second example i will include just one package (sengrid), with first approach i must include two packages (nodemailer and nodemailer-sendgrid-transport). I see that first approach is bigger abstraction over second in that i can update or switch entirely to some other service-transport (gmail for example) or can i? But in other hand i don't see situation where it would be appropriate to switch between different transport objects.

侧面问题这是如何在此使用模板解决方案。我没有在官方指南中看到任何有关模板的内容,也没有看到以下内容: https://github.com/sendgrid/sendgrid-nodejs 或: https://github.com/andris9/Nodemailer

Side question appart all of this is how to use templates with this solutions. I dont see in official guides anything about templates nor at: https://github.com/sendgrid/sendgrid-nodejs nor at: https://github.com/andris9/Nodemailer:

除了这之外,电子邮件模板完全是另外一回事了,我需要安装可以处理它的新软件包吗?
最后,我觉得我的提问很迟钝。 / p>

Email templates are whole different story apart this and i need to install new package which will deal with it?
In the end I feel like I'm posted very retarded question.

推荐答案

我已经将nodemailer与Mandrill结合使用了,没有任何问题。

I have used nodemailer with Mandrill without any problems.

这是适用于我的代码,但您没有提到:

This is the code that works in my case, but you mentione not in yours:

// 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
    }
});

请注意,凭据存储在mainConfigFile中,但很明显是什么意思。

Please note that credentials are stored in mainConfigFile, but it is clear what is the intention.

我认为您应该对nodemailer感到满意。

I think you shoudl be ok with nodemailer.

您能否提供有关收到的错误的更多详细信息?

Can you provide more details regarding the error you receive?

这篇关于节点-用于发送电子邮件,sendgrid和nodemailer之一或组合的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆