OpenMail Sample Code

Enable the Subscriptions block here!

Flow of Your Application


Authentication

Authenticate using OpenAuth, get an authentication Token using getToken and screenname details using getInfo - OpenAuth

Generic Functions to Request and Accept Data


/**
   requestData accepts a Object containing the API details 
   
   1. We call the API URI between the <head> </head> of the HTML file and then
   handle the response via a callback - acceptData
   2. It would look something like this 
   	<head>
	<script id="MailData-0" type="text/javascript" src="https://api.mail.aol.com
/mail/newMailCount?f=json&a=%2FwEAAAAApm%2Fe%2FVniGzrGTEHvmTkxmLyBomdBaM%2F
l%2FgMmF5nq5KBvmPv2GgRur9NFXJe1UJzCdX0ItpOsObYXozp5Bo76oEfwAyBDDxebPMDq245E
onJswDBvk68qd5AIMHjGwvmm6fQKeBSKDmKWhLN9DrUzjZNs9uw%3
D&devId=ss1r22V1Du1X8FH2&c=acceptData&r=1"/> </head> */ var MailData = []; function requestData(transactionObject) { var len = MailData.length; transactionObject.timestamp = Date.parse(new Date()); MailData[len] = {}; MailData[len].oScript = document.createElement("script"); MailData[len].oScript.setAttribute("id","MailData-" + len); MailData[len].oScript.setAttribute("type","text/javascript"); MailData[len].objData = transactionObject; if(transactionObject.dataURI.indexOf("?") == -1) { transactionObject.dataURI+="?r=" + len } else { transactionObject.dataURI+="&r=" + len } MailData[len].oScript.setAttribute("src",transactionObject.dataURI); document.getElementsByTagName("head")[0].appendChild(MailData[len].
oScript); } function acceptData(json) { var requestId = parseInt(json.response.requestId); var code = parseInt(json.response.statusCode); var type = MailData[requestId].objData.type; if(code != 200) { // Handle error conditions here } // Check the type of data and call the respective data handler if (type == "getCount") { getCountcallback(json); } else if (type == "getList") { getListCallback(json); } }

Retrieve the New Mail Count Using the newMailCount API

Your function will look something like

/**
  getCount() - pass the transaction Object which has dataURI and the
  type of data being requested

  Parameters : 
	  f = type of response requested 
	  a = authentication token
	  devId = developer key
	  c = callback to handle the response
  
 */

function getCount () {
	var tObj = {
			dataURI: "https://api.mail.aol.com/mail/newMailCount" + "?f=
json&a=" + tokenvalue + "&devId=" + devId + "&c=acceptData", type:"getCount" } requestData(tObj); } and the callback function will handle the response /** getCountcallback(json) - Display the number of mails via the json object */ function getCountcallback(json) { var messageCount = json.response.data.mailFolderCount.mailFolderData.
mailFolderType[0].count; alert("Mail count is" + messageCount); }

Get the Actual Mail Details Through newMailList


/**
	getList() - prepare the object to pass to the API URL
	f - type of data
	items - number of mails that can be retrieved (maximum is 75)
	a - authentication token
	devId - developer key
	c - callback function
*/

function getList() {
	var tObj = {
		dataURI: "https://api.mail.aol.com/mail/newMailList" + "?f=json&
items=75&a=" + tokenvalue + "&devId=" + devId + "&c=acceptData", type:"getList" } } /** getListCallback - handle the json data Extract the mail subject, date and sender */ function getListCallback (json) { if(json.response.statusCode == 200) { // You can get the count here as well var messageCount = json.response.data.mailList.messageList[0].
messageCount; // Actual Messages var messages = json.response.data.mailList.messageList[0].
messages; if (json.response.statusCode == 451 || json.response.statusCode
== 500){ alert("Mail could not be retrieved!"); return; } document.write ("Total number of emails you have" + messageCount "); // Emails for (var i=0; i < messages.length; i++) { var sender = messages[i].sender; var subject = messages[i].subject; var date = messages[i].sentOn; document.write (sender + "-------" + subject + "------" +
date "); } } }

Download and View Sample Code