Question

I have a very simple meteor application. I want to utilize the postmark api in this application lucky for me they have a node.js module.
https://github.com/voodootikigod/postmark.js
I have successfully installed this module to node and can see it sitting there.
Every resource I have touched on has told me that this should now be accessible via Meteor with a simple require.
This is my code so far.

    if (Meteor.isClient) {
      Template.hello.greeting = function () {
        return "Welcome to postmarkapp.";
      };

      Template.hello.events({
        'click input' : function () {
          // template data, if any, is available in 'this'
          if (typeof console !== 'undefined')
            Meteor.call('sendMail',function(error,result){
              console.log(result);
            });
          }
      });
    }

    if (Meteor.isServer) {
    var require = __meteor_bootstrap__.require;
    postmark = require("postmark")('API_KEY');
        Meteor.methods({
          sendMail: function() {

            return postmark;

          }
        });

    }

Now I don't get any errors when I run this method however I do get an empty object with no methods. Looking at the postmark module I should get an object with one method, "send".

Can anyone enlighten me on where I could be going wrong? I think it may be in the including of the node module and the use of that module in the Meteor app.

I have looked at the documentation of Meteor extensively and cant seem to find anything related to this subject.

Thank you in advance.

Was it helpful?

Solution

This code is trying to return the postmark.send function to the client. This is not possible. Methods can only return JSON serializable values.

You should be able to use postmark's send function inside the method body, though depending on its interface you might need to wrap it in a fiber.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top