Mandrill JSON API with Meteor HTTP.post -


i'm stringifying emaildata , sending mandrill url no success:

meteor.methods({     'sendprojectapprovedemail'(projectid){         check(projectid, string);          let project = projects.findone({_id: projectid});         let user = meteor.users.findone({_id: project['userid']});          let message = `<p>hola ${user['services']['facebook']['first_name']}, enviamos este correo para notificarte que tu proyecto:</p>`;          let emaildata = {             "key": meteor.settings.mandrillapikey,             "message": [{                 "html": message,                 "subject": "tu proyecto ha sido aprobado",                 "from_email": "mail@mail.com",                 "from_name": "name.com",                 "to": [{                   "email": user['services']['facebook']['email'],                   "name": user['services']['facebook']['first_name'],                   "type": "to"                 }],                 "headers": {                   "reply-to": "mail@mail.com"                 },                 "track_opens": true,             "track_clicks": true,             "inline_css": true             }],             "async": false         };          http.post('https://mandrillapp.com/api/1.0/messages/send.json', {             data: json.stringify(emaildata),             headers: {                 'content-type': 'application/json; charset=utf-8'             }         }, function(error, data){             if (error) { console.log(error) }             else { console.log(data) }         });     } }); 

the json.stringify output following:

console.log(json.stringify(emaildata));

{"key":"xxxxxx...","message":[{"html":"<p>hola gustavo, enviamos este correo para notificarte que tu proyecto:</p>","subject":"tu proyecto ha sido aprobado","from_email":"mail@mail.com","from_name":"developerfullstack.com","to":[{"email":"mail@gmail.com","name":"gustavo","type":"to"}],"headers":{"reply-to":"contacto@developerfullstack.com"},"track_opens":true,"track_clicks":true,"inline_css":true}],"async":false} 

but response returns 500 error:

{ [error: failed [500] {"status":"error","code":-1,"name":"validationerror","message":"you must specify key value"}] 

i've tried:

  • let emaildata = [{//...}]
  • let emaildata = {"key": "xxx...", "message": {//...}}

as other answers suggest, no success.

update

for record, made work with:

let emaildata = {     "key": meteor.settings.mandrillapikey,     "message": {         "html": message,         "subject": "tu proyecto ha sido aprobado",         "from_email": "mail@mail.com",         "from_name": "name.com",         "to": [{           "email": user['services']['facebook']['email'],           "name": user['services']['facebook']['first_name'],           "type": "to"         }],         "headers": {           "reply-to": "mail@mail.com"         },         "track_opens": true,         "track_clicks": true,         "inline_css": true     },     "async": false };  http.post('https://mandrillapp.com/api/1.0/messages/send.json', {     data: emaildata,     headers: {         'user-agent': 'meteor app devfs@1.0.0'     } }, function(error, data){     if (error) { console.log(error) }     else { console.log(data) } }); 

well, i'll show how i'm sending emails mandrill:

http = npm.require("https");  meteor.methods({      sendemail: function(data) {          var message = {             'subject': data.subject,             'text': data.text,             'html': data.html,             'from_email': "contact@mydomain.com",             'from_name': "mydomain",             'to': [{ 'email': data.email, 'name': data.name, 'type': "to" }],             'headers': { 'reply-to': "contact@mydomain.com" },             'important': false,             'track_opens': false,             'track_clicks': false,             'auto_text': true         };          var options = {             "method": "post",             "hostname": "mandrillapp.com",             "port": null,             "path": "/api/1.0/messages/send.json",             "headers": {                 "content-type": "text/html; charset=utf-8"             }         };          var req = http.request(options, function(res) {             var chunks = [];             res.on("data", function(chunk) {                 chunks.push(chunk);             });             res.on("end", function() {                 var body = buffer.concat(chunks);                 console.log(body.tostring()); // response mandrill             });         });          req.write(json.stringify({             'key': meteor.settings.mandrill.apikey,             'message': message,             'async': false         }));          req.end();     } }); 

you don't need packages this.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -