Meteor deploy - MAIL_URL not being set - meteor

I recently started deploying a meteor app off of my local machine and it seems that the MAIL_URL property is not being set when deploying to a *.meteor.com domain. No matter what I have tried the email is sent via the default MailGun
What I have tried so far.
Verified that process.MAIL_URL is set and works locally - ensures
that I am setting MAIL_URL correctly
Verified that process.MAIL_URL
is set on *.meteor.com domain by checking meteor logs - ensures that
the process.env settings are being set on *.meteor.com
Tried multiple *.meteor.com domains - ensures it was not a subdomain specific
issue
Tried multiple smtp providers: gmail and Mandrill - ensures
that it was not an issue with the smtp provider
Tried creating a simple app with a simple test email button - ensures problem was not
related to my app code
Nothing works. With the simple app, my code is the following:
if (Meteor.isClient) {
Template.hello.greeting = function () {
return "Welcome to testmail.";
};
Template.hello.events({
'click input' : function () {
console.log("calling send mail");
Meteor.call('sendEmail',
'xxx#gmail.com',
'xxx#domain.com',
'Hello from Meteor!',
'This is a test of Email.send.');
}
});
}
if (Meteor.isServer) {
// In your server code: define a method that the client can call
Meteor.methods({
sendEmail: function (to, from, subject, text) {
check([to, from, subject, text], [String]);
// Let other method calls from the same client start running,
// without waiting for the email sending to complete.
this.unblock();
Email.send({
to: to,
from: from,
subject: subject,
text: text
});
}
});
Meteor.startup(function () {
// code to run on server at startup
process.env.MAIL_URL = 'smtp://blahblah:token#smtp.mandrillapp.com:587/';
console.log(process.env);
});
}
I am out of ideas at this point. Has anybody else experience this before and what was the resolution? Thanks.

By default meteor deploy can only use mailgun since you can't alter the environmental variables on meteor deploy hosting. Additionally meteor deploy hosting uses a galaxy configuration which takes precedence over environmental variables.
If you take a look at [this file] meteor deploy hosting uses some kind of App configuration that configures it over the environmental variable (see https://github.com/meteor/meteor/blob/devel/packages/email/email.js#L42). This is part of the galaxy configuration engine.
You have to modify the Email package to use a custom smtp server. To do this :
get the files from https://github.com/meteor/meteor/tree/devel/packages/email and place them in a directory in your project /packages/email.
add this package to your meteor project with meteor add email. It should override the default meteor-core package. If it says already using, thats okay.
Modify /packages/email/email.js around line 36 to be:
var smtpPool = makePool("<YOUR CUSTOM MAIL_URL>");
Then you should be good to go. Meteor should use this smtp host instead, even on meteor.com hosting.

Related

What path should I use for Meteor's Webapp API?

I'm using Meteor v1.9 Webapp API to have my app listen to HTTP requests, specifically from a link to the app itself from a website, let's say example.org.
The documentation says to use
WebApp.connectHandlers.use([path], handler)
Where the [path] is defined as such:
path - an optional path field. This handler will only be called on
paths that match this string. The match has to border on a / or a ..
For example, /hello will match /hello/world and /hello.world, but not
/hello_world.
My question:
Let's say my meteor application is hosted on abc.com and the POST data being sent over to it is from example.org (where the link to abc.com is as well).
For the [path] argument mentioned above, in this case, should I have it as "/example" since example.org is where my app is listening to requests from (getting the POST data)? Or does it have to be a different format? I tried the former, but it doesn't seem to be working for it, so I'm trying to find the root of the issue.
Additional information that might be useful: I know it says 'optional' so I tried omitting it, but when I tested it out via 'meteor run' where it runs off of localhost:3000, it just yielded a blank page, with no errors and a success sent back, probably because it uses a GET request instead of POST.
My code for the webapp in my meteor application is as follows:
WebApp.connectHandlers.use("/[example]", async (req, res, next) => {
userName = req.body;
res.writeHead(200);
res.end();
});
Also technically my meteor application is built/bundled and deployed as a Node.js application on the website, but that shouldn't affect anything regarding this as far as I could tell.
That path is the path (part of the URL) on your meteor server. So in your example, for instance,
WebApp.connectHandlers.use("/example", async (req, res, next) => {
userName = req.body;
res.writeHead(200);
res.end();
});
means that you will need to send your POST requests to abc.com/example.

How can I authenticate via Firebase Google Auth on localhost

I'm building a site with emberfire and using firebase. Everything seems to be set up fine regarding credentials, and I can read/write to the firebase database while developing locally, but every time I try to authenticate via the Google Popup it pops up fine with my Google accounts listed, and when I select my account it errors with this error object:
code: "auth/network-request-failed", message: "A network error (such as timeout, interrupted connection or unreachable host) has occurred."
I assume I'm simply missing a setting somewhere but for the life of me I cannot find it. Here's the code to get the popup and response:
const provider = new firebase.auth.GoogleAuthProvider();
this.firebaseApp.auth().then(auth => {
/* Firebase SDK calls */
auth.signInWithPopup(provider).then(function(response) {
console.log(response);
}).catch(function(error) {
console.log(error);
});
});
I am using EmberJS with emberfire.
In my environment I had host: 'api', and when removing that authentication works, so it must be one of the adapters that is used.

Upload TLS client certificate to Firebase cloud functions

I'm trying to figure out if it is possible to upload a TLS client certificate to be used for my cloud functions in firebase. The TLS client certificate is required by a third-party payment solution called Swish.
This is my first firebase project and it seems silly that a small issue like this will render the platform unusable for me..
After some headache and trying I found a quite easy way to solve swish-payments through cloud functions:
Using request-js instead of the built in libraries, I only need to build the options object to use in the request.post() method as following:
const swishOptions = {
url: 'LINK TO SWISH SERVER',
json: true,
pfx: fs.readFileSync('cert.p12'),
passphrase: 'swish',
body: swishRequestBody
}
The cert.p12-file should be placed in the same folder as index.js and will be uploaded together with the functions.
rq.post(swishOptions, (err, res) => {
if (err){
console.log('payment creation error: ' + JSON.stringify(err))
reject(err)
}
if (res){
console.log('Payment-token: ' + res.headers.paymentrequesttoken)
}
});
The body-object should contain all fields specified in the Swish API, use console.log() to read the error-messages from the Swish-server.

meteor resetpassword is not working

i'm making custom meteor account.
referring to this url >> Building a customized accounts ui for Meteor
but i have problem.
if (Accounts._resetPasswordToken) {
Session.set('resetPassword', Accounts._resetPasswordToken);
}
client side called this code is always undifined.(Accounts._resetPasswordToken)
finally i want to call
Accounts.resetPassword(Session.get('resetPassword'), pw, function(err){

Creating custom CLI tools for a Meteor app

I'm working on a Meteor app (a port from a PHP project) and I need to be able to run commands on my app from the server for various operations like clearing caches, aggregating data, etc. These commands need to be run from shell scripts and crontab. I've seen other people ask this question and apparently there's no official way to do it yet.
I read a suggestion of using Meteor methods and just calling them from the client's JS console with a password. This doesn't solve my problem of running them from the CLI, but it did give me an idea:
Would it be possible to use a headless browser (like PhantomJS) to connect to my app and execute Meteor.call() to simulate a CLI tool with arguments passed to the method? If possible, does anyone know how I might accomplish this?
Thanks!
EDIT: Updated to use Iron Router, the successor to Meteor Router.
There's no need for a headless browser or anything complicated. Use Meteorite to install Iron Router and define a server-side route:
Router.map(function () {
this.route('clearCache', {
where: 'server',
action: function () {
// Your cache-clearing code goes here.
}
});
});
Then have your cronjob trigger an HTTP GET request to that URI:
curl http://yoursite.com/clearCache
When the Meteor server receives the GET request, the router will execute your code.
For a little bit of security, add a check for a password:
Router.map(function () {
this.route('clearCache', {
path: '/clearCache/:password',
where: 'server',
action: function () {
if (this.params.password == '2d1QZuK3R3a7fe46FX8huj517juvzciem73') {
// Your cache-clearing code goes here.
}
}
});
});
And have your cronjob add that password to the URI:
curl http://yoursite.com/clearCache/2d1QZuK3R3a7fe46FX8huj517juvzciem73
Original Post:
There's no need for a headless browser or anything complicated. Use Meteorite to install Meteor Router and define a server-side route:
Meteor.Router.add('/clearCache', function() {
// Your cache-clearing code goes here.
});
Then have your cronjob trigger an HTTP GET request to that URI:
curl http://yoursite.com/clearCache
When the Meteor server receives the GET request, the router will execute your code.
For a little bit of security, add a check for a password:
Meteor.Router.add('/clearCache/:password', function(password) {
if (password == '2d1QZuK3R3a7fe46FX8huj517juvzciem73') {
// Your cache-clearing code goes here.
}
});
And have your cronjob add that password to the URI:
curl http://yoursite.com/clearCache/2d1QZuK3R3a7fe46FX8huj517juvzciem73
Check out this Meteor app, which does exactly that:
http://meteor-shell.meteor.com/
Why do you need a CLI tool when you could just store some scripts on the server and execute them from an admin interface in your Meteor app?
Got the same question yesterday. Found this Package, but have not yet tried it
https://github.com/practicalmeteor/meteor-mcli
Overview
A meteor package and command line tools for creating and running
command line / cli programs with meteor.
Incentive
To be able to reuse the same code of your meteor app in your command
line programs, instead of having to create a separate node / npm code
base with lot's of code duplicated from your meteor app.

Resources