Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mandrill #1000

Closed
cyboolo opened this issue Mar 12, 2016 · 6 comments
Closed

Mandrill #1000

cyboolo opened this issue Mar 12, 2016 · 6 comments

Comments

@cyboolo
Copy link

cyboolo commented Mar 12, 2016

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": "support@cyboolo.com",
            "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`

@flovilmart
Copy link
Contributor

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

@cyboolo
Copy link
Author

cyboolo commented Mar 12, 2016

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

@flovilmart
Copy link
Contributor

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.

@cyboolo
Copy link
Author

cyboolo commented Mar 12, 2016

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

@vikas230428
Copy link

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: "xxxxx@gmail.com",
                                  from_name: "pqr",
                                  to: [
                                       {
                                       email: "xxxxxxxxxx@gmail.com",
                                       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");
                                  }
                                  });
               });`

@davimacedo
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants