Sending Email Using Gmail SMTP - Meteorjs

Hi, I'm trying to set up my gmail account to send emails for my Meteor app, not so easy so far

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 test email is never sent with the error code below saying that I did not 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 ====== 

Is this possible, I am running this on C9?

thanks

+5
source share
4 answers

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

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

Essentially, you can pass JSON to the meteorite when you launch it using -settings. They will be available only on the server side, unless they are wrapped under a β€œpublic” root object.

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

This is a job to work without envrionmental variables. Since the main mail package always looks at the MAIL_URL environment variable, you may have to send email through another service provider / provider.

Mandrill (by Mailchimp) has a significant free level and will allow you to send transactional emails. You can even create a mail template in mailchimp, export to HTML, import into mandrill, and pass in the merge variables in your API calls.

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

Hope this helps!

Elliot

+2
source

but decided to answer any question.

I did not, and I cannot set the env variable for C9 or my site, therefore therefore.

+1
source

The Meteor.startup(callback) method is executed at the end of Meteor initialization, but you send your email before starting, so you must send it to the same block after process.env.MAIL_URL ..

0
source

You can set environment variables using C9! You just transmit it when you launch a meteorite.

BUT you cannot send email using SMTP, although on c9!

To make my life easier, I just don't check my letters on c9 with Meteor. If I absolutely need to bypass the email function and instead use a custom mail client that sends using the MailGun REST API (NOT SMTP !!) See Sending Email Using Gmail SMTP - Meteorjs

0
source

All Articles