Page 1 of 1

sending email from server code

Posted: Sat Mar 19, 2016 7:24 am
by EJLD

Hi There,

I have been using the Mandrill service to send email from the app with ajax. it works well as expected when from the app.
however I need to schedule a service script on daily basis, I have checked the Mandrill website. the API in nodejs looks like :

Code: Select all

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

var message = {
"html": msg,
"subject": '....blablabla....',
"from_email": "noReply@........io",
"to": [{
"email": query3.email,
"name": query3.username,
"type": "to"
}],

};

the error msg says that "require" is not defined.
would you have the proper code in server code to replace that "require" ?

looking forward to receiving you smart advice as usal !

Eric


sending email from server code

Posted: Sat Mar 19, 2016 8:16 am
by EJLD

sorry to disturb you with that matter, but going through the Mandrill site, I found also the CURL command.
I tried in the server code but not much success either.
could you tell me how to insert the curl script ?

curl -A 'Mandrill-Curl/1.0'
-d '{"key":"myKey","message":{"html":'+msg+',"subject":"xxx","from_email":"noReply@xxxxio","from_name":"noReply","to":[{"email":'+query3.email+',"name":'+query3.username+',"type":"to"}]}'
https://mandrillapp.com/api/1.0/messa...

thk you very much


sending email from server code

Posted: Sat Mar 19, 2016 8:41 am
by EJLD

me again, this time I read your dev blog again and found that it shld be written in JSON. I tried but have an error msg still about "key"

Code: Select all

 { 
   "key": "xxxxxxxx", 
   "message": { 
    "html": msg, 
    "subject": 'xxxxxx', 
    "from_email": "a href="mailto:noReply@xxxxxxxx.io" rel="nofollow"noReply@xxxxxxxx.io/a", 
    "from_name": "noReply", 
    "to": [{ 
       "email": query3[i].email, 
       "name": query3[i].username, 
       "type": "to" 
      }] 
     } 
 }

sending email from server code

Posted: Tue Mar 22, 2016 11:01 pm
by EJLD

Hi There, I know this question is about custom code.
however, I am sure that you guys are expert enough to know what goes wrong at first glance (not like me :) )
may i ask you for quick advice ?
thk you very much in advance,
Eric


sending email from server code

Posted: Wed Mar 23, 2016 2:24 am
by Vinny B

Surprised no response if four days that is odd.
Did u see this?

https://parse.com/questions/sometimes...

Parse.Cloud.httpRequest({ method: 'POST', headers: {

'Content-Type': 'application/json; charset=utf-8'
}, url: 'https://mandrillapp.com/api/1.0/messa...', body: {

key: "yourAPIKey-xxxxxxxxxx",
message: {
html: "your html message, or a text message as text: instead of html:",
subject: "Your Subject",
from_email: "a href="mailto:from@email.com" rel="nofollow"from@email.com/a",
from_name: "John Doe",
to: [
{
email: "a href="mailto:to@email.com" rel="nofollow"to@email.com/a",
name: "John Doe"
}
]
}
}, success: function(httpResponse) {

console.log(httpResponse);
}, error: function(httpResponse) {

console.error(httpResponse);
} });


sending email from server code

Posted: Fri Mar 25, 2016 3:14 pm
by EJLD

Hi Vinny B, thk you for your msg. that saved me. I struggled still but found the way to send email from server code. cheers!


sending email from server code

Posted: Sat Mar 26, 2016 1:16 am
by EJLD

Hi there, just a quick update to this thread.
if anybody interested in Mandrill emails, I can send from server code with the following script:

xxxxxxxxxxxxxxxxxxxxxxxxxxxx

var XHRResponse = XHR2.send('POST', 'https://mandrillapp.com/api/1.0/messa...', {

Code: Select all

 "headers": { 
 'Content-Type': 'application/json; charset=utf-8' 
 }, 
 "body": { 
   "key": "Z3H... you key ...Rhw", 
   "message": { 
    "html": yourHTML str , 
    "subject": "... yourSubject ... ", 
    "from_email": "yourEmail", 
    "from_name": "yourName", 
    "to": [{ 
       "email": destinationEmail, 
       "name": destinationName, 
       "type": "to" 
      }] 
     } 
 } 
}); 

Apperyio.response.success(XHRResponse.body, "application/json"); 

}

xxxxxxxxxxxxxxxxxxxxxxx

ATB
Eric