使用Gmail SMTP发送电子邮件-Meteorjs [英] Sending email using Gmail SMTP - Meteorjs

查看:137
本文介绍了使用Gmail SMTP发送电子邮件-Meteorjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置我的Gmail帐户来为我的Meteor应用发送电子邮件,到目前为止还不太容易

Hi I am trying set up my gmail account to send email for my Meteor app, not very easy so far

server.js

server.js

Meteor.startup(function () {
  smtp = {
    username: 'xxxxx',   // eg: server@gentlenode.com
    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: "meteor.email.2014@gmail.com",
  to: "xxxx@gmail.com",
  subject: "Meteor Can Send Emails via Gmail",
  text: "Its pretty easy to send emails via gmail."
});

并且永远不会发送带有以下错误代码的测试电子邮件,表明我尚未设置环境变量。

And the testing email is never sent with the below error code saying that I havent set the environment variable.

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: meteor.email.2014@gmail.com
I20150715-18:14:02.643(0)? To: xxxx@gmail.com
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上运行它?

Could this be due I am running this on C9?

谢谢

推荐答案

不允许设置环境变量。也许您可以设置 Meteor.settings 对象而不是环境变量?

Sucks that cloud9 does not permit the setting of environment variables. Perhaps you can set the Meteor.settings object rather than an environment variable?

http://docs.meteor.com/#/full/meteor_settings

本质上,当您使用--settings启动JSON时,可以将其传递给流星。除非包装在根的公共对象下,否则它们仅在服务器端可用。

Essentially, you can pass JSON to meteor when you start it using --settings. These will be available on the server side only, unless wrapped under a "public" object of the root.

{
  'public': {
     'some-setting': 'some-value'
  },
  'other-setting': 'other-value'
}

这是解决无环境变量的一种变通方法。由于核心电子邮件包始终查看MAIL_URL环境变量,因此您可能需要通过其他服务/提供者发送电子邮件。

That is a work around for dealing with no envrionmental variables. As the core email package always looks at the MAIL_URL environmental variable, you will probably need to send email through another service/provider.

Mandrill (由Mailchimp提供)具有相当大的免费层,可让您发送交易电子邮件。您甚至可以在mailchimp中制作一个邮件模板,导出为HTML,导入为mandrill并在您的API调用中传递合并变量。

Mandrill (by Mailchimp) have a sizeable free tier and will allow you to send transactional email. You can even make a mail template in mailchimp, export to HTML, import to mandrill and pass in merge variables in your API calls.

更好的是,用于写入Mandrill API的ass包。 https://atmospherejs.com/wylio/mandrill

Better yet, there is a kick-ass package for writing to the Mandrill API. https://atmospherejs.com/wylio/mandrill

希望有帮助!

埃利奥特

这篇关于使用Gmail SMTP发送电子邮件-Meteorjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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