parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Mandrill

Open cyboolo opened this issue 10 years ago • 6 comments

Before I update to last version of parse server, this function worked perfectly. Now it is not working...

Could you explain me what is wrong please?

`Parse.Cloud.define("msg_invit", function(request, response) {

var to_userID = request.params.A;

Parse.Cloud.useMasterKey();

var query = new Parse.Query(Parse.User);

query.get(to_userID, {
success: function(user) {

var email = user.get("email");
var from_username = request.params.B;

////////////////////
                var mandrill = require('mandrill-api/mandrill');
        var mandrill_client = new mandrill.Mandrill('mykey');

        var template_name = "nouveau-contact";
        var template_content = [{
            "name": "example name",
            "content": "example content"
            }];
        var message = {
            "html": "",
            "subject": "Nouveau contact lab",
            "from_email": "[email protected]",
            "from_name": "cyboolo",
            "to": [{
                "email": email,
                "type": "to"
            }],
            "global_merge_vars": [{
                "name": "username",
                "content": from_username
            }]
        };

        mandrill_client.messages.sendTemplate({"template_name": template_name, "template_content": template_content,"message": message, "async": true}, function(result) {
            response.success(result);
        }, function(e) {
            response.error('A mandrill error occurred: ' + e.name + ' - ' + e.message);
            });
//////////////////

},
    error: function(user, error) {
    // Show the error message somewhere and let the user try again.
    console.log(error);
    console.error(error);
    response.error(error.code);  

    }
  });

}); //Fin`

cyboolo avatar Mar 12 '16 15:03 cyboolo

can you please describe the error? user is not found? mandrill is not sending? template is not found?

flovilmart avatar Mar 12 '16 15:03 flovilmart

I have this response on the client:

XMLHttpRequest cannot load https://labcyboolo.herokuapp.com/parse/functions/msg_invit. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://cyboolo.worldsecuresystems.com' is therefore not allowed access. The response had HTTP status code 503.

On heroku: 2016-03-12T14:59:43.429143+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/parse/functions/msg_invit" host=labcyboolo.herokuapp.com request_id=f3598f9c-94ae-41b7-8cf6-31e823d78d04 fwd="77.146.194.164" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0

I think this is not a problem of finding user or template. Yesterday before I udpated to new version of parse server it worked perfectly.

I think the problem must come from how to config mandrill with this new version of parse server... Do i have to add something in the index.js? Before it was not necessary

Do i have to install mandrill npm in some way on heroku? Because I installed my app with heroku button and it installs node buildpack but how can I be sure mandrill is present?

Thanks for your help

cyboolo avatar Mar 12 '16 15:03 cyboolo

how do you run parse-server on heroku? parse-server sets 'Access-Control-Allow-Origin':'*' on every requests so that seems to be a problem with your setup.

flovilmart avatar Mar 12 '16 15:03 flovilmart

Actually it is because I did not declare mandrill as dependency in package.json:

"mandrill-api":">=1.0.2"

Sorry and thank you for your help

cyboolo avatar Mar 12 '16 15:03 cyboolo

Hi

I am also not able to send email after migration to parse server the mandrill cloud code returns 'internal server error' my mandrill api version is 1.0.45.

@cyboolo Can you please tell me how would the be resolved below is my function reside in cloud/main.js and pushed to heroku.

`Parse.Cloud.define("sendMail", function(request, response) { var Mandrill = require('mandrill'); Mandrill.initialize('xxxxxx-xxxxx');

               Mandrill.sendEmail({
                                  message: {
                                  text: "ffff",
                                  subject: "hello",
                                  from_email: "[email protected]",
                                  from_name: "pqr",
                                  to: [
                                       {
                                       email: "[email protected]",
                                       name: "trump"
                                       }
                                       ]
                                  },
                                  async: true
                                  },{
                                  success: function(httpResponse) {
                                  console.log(httpResponse);
                                  response.success("Email sent!");
                                  },
                                  error: function(httpResponse) {
                                  console.error(httpResponse);
                                  response.error("Uh oh, something went wrong");
                                  }
                                  });
               });`

vikas230428 avatar Apr 24 '16 06:04 vikas230428

Be sure you have installed mandrill api: npm install mandrill-api Try requiring mandrill by this way: var mandrill = require('mandrill-api/mandrill'); Take a look in the following file as an implementation reference: https://github.com/back4app/parse-server-mandrill-adapter/blob/master/index.js

davimacedo avatar Apr 24 '16 18:04 davimacedo