您好,我正在尝试设置我的 Gmail 帐户来为我的 Meteor 应用程序发送电子邮件,到目前为止还不是很容易
服务器.js
Meteor.startup(function () {
smtp = {
username: 'xxxxx', // eg: [email protected] /cdn-cgi/l/email-protection
password: 'YYYYYYYY', // eg: 3eeP1gtizk5eziohfervU
server: 'smtp.gmail.com', // eg: mail.gandi.net
port: 465
}
process.env.MAIL_URL = 'smtp://' + encodeURIComponent(smtp.username) + ':' + encodeURIComponent(smtp.password) + '@' + encodeURIComponent(smtp.server) + ':' + smtp.port;
});
Email.send({
from: "[email protected] /cdn-cgi/l/email-protection",
to: "[email protected] /cdn-cgi/l/email-protection",
subject: "Meteor Can Send Emails via Gmail",
text: "Its pretty easy to send emails via gmail."
});
并且测试电子邮件永远不会发送以下错误代码,表明我尚未设置环境变量。
I20150715-18:14:02.641(0)? ====== BEGIN MAIL #0 ======
I20150715-18:14:02.642(0)? (Mail not sent; to enable sending, set the MAIL_URL environment variable.)
I20150715-18:14:02.643(0)? MIME-Version: 1.0
I20150715-18:14:02.643(0)? From: [email protected] /cdn-cgi/l/email-protection
I20150715-18:14:02.643(0)? To: [email protected] /cdn-cgi/l/email-protection
I20150715-18:14:02.643(0)? Subject: Meteor Can Send Emails via Gmail
I20150715-18:14:02.643(0)? Content-Type: text/plain; charset=utf-8
I20150715-18:14:02.643(0)? Content-Transfer-Encoding: quoted-printable
I20150715-18:14:02.644(0)?
I20150715-18:14:02.644(0)? Its pretty easy to send emails via gmail.
I20150715-18:14:02.645(0)? ====== END MAIL #0 ======
这可能是因为我在 C9 上运行这个吗?
Thanks
糟糕的是cloud9不允许设置环境变量。也许你可以设置Meteor.settings
对象而不是环境变量?
http://docs.meteor.com/#/full/meteor_settings http://docs.meteor.com/#/full/meteor_settings
本质上,当你使用--settings启动它时,你可以将JSON传递给meteor。这些仅在服务器端可用,除非包装在根的“公共”对象下。
{
'public': {
'some-setting': 'some-value'
},
'other-setting': 'other-value'
}
这是一种处理无环境变量的解决方法。由于核心电子邮件包始终查看 MAIL_URL 环境变量,因此您可能需要通过其他服务/提供商发送电子邮件。
Mandrill http://mandrill.com/(由 Mailchimp 提供)有相当大的免费套餐,可以让您发送交易电子邮件。您甚至可以在 mailchimp 中制作邮件模板、导出到 HTML、导入到 mandrill 并在 API 调用中传入合并变量。
更好的是,有一个用于写入 Mandrill API 的强大包。https://atmospherejs.com/wylio/mandrill https://atmospherejs.com/wylio/mandrill
希望有帮助!
Elliott
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)