Node.js


Loading the support system

loading...

 

npm users can install the NodeJS wrapper directly using npm install. To install the wrapper simply run the following in your application folder:

$npm install reachmailapi

More details on the NodeJS wrapper can be found here:
https://www.npmjs.org/package/reachmailapi

//Include the wrapper
var reachmail = require('./reachmailapi.js');

//inialize the wrapper to the variable api using a token generated from the User Interface at https://go.reachmail.net
var api = new reachmail({token: 'YoUrSeCr3tTokenG03sH3rE'});

//The following builds the content of the message
var body={
	FromAddress: 'from@domain.tld',
	Recipients: [
	{
		Address: 'rcpt@domain.tld'
        },
	{
		Address: 'rcpt2@domain.tld'
	}
	],
  	Headers: { 
		Subject: 'Test Subject Goes Here' , 
		From: 'From Name <from@domain.tld>', 
		'X-Company': 'Company Name', 
		'X-Location': 'Your Location Header' 
	}, 
	BodyText: 'this is the text version of the ES API test',
	BodyHtml: 'this is the HTML version of the ES API test', 
	Tracking: true
};
//JSON encode the message body for transmission
jsonBody = JSON.stringify(body);

/* 
The function below retreieves the account GUID. Only when succefful will the 
function proceed to them schedule the message for delivery.
Information is printed to screen through the use of console.log(...)
*/
api.AdministrationUsersCurrent(function (http_code, response) {
	if (http_code===200) {
		AccountId=response.AccountId; //extracts account GUID from response obj
		console.log("Success!  Account GUID: " + AccountId); //prints out the Account GUID
		//Next Function sends the message
		api.easySmtpDelivery(AccountId, jsonBody, function (http_code, response) {
			if (http_code===200) {
				console.log("successful connection to EasySMTP API");
				console.log(response);
			}else { 
				console.log("Oops, looks like an error on send. Status Code: " + http_code);
				console.log("Details: " + response);
			}
		});
	} else {
		console.log("Oops, there was an error when trying to get the account GUID. Status Code: " + http_code);
		console.log("Details: " + response);
	}
});</from@domain.tld>