<%
idClient = "Your Customer ID"
APIkey = "Your API Key" 'On demand  
email = "[email protected],,,,,,,,,,,,,,,,,,,,,,,,,"
message = "<html><head></head><body>Send from API</body></html>"
subject = "Send from API with Visual Basic"
AddressBookName = "Name of the AddressBook"

AddressBookID = addAddressBook(idClient,APIkey,AddressBookName) 
addEmail AddressBookID, email, idClient, APIkey
MessageId = addMessage(idClient,APIkey,message,subject)
ExpID = getIdExp(idClient,APIkey)
addSend idClient,APIkey,AddressBookID,MessageId,ExpID

public function addAddressBook(idClient,APIkey,AddressBookName) 
	url = "https://DomainName/v2/addressbook/add.xml"
	formdata = "IDClient="& idClient &"&APIKey="& APIkey & "&Title="& AddressBookName & "&Type=1" & ""
	tagName = "AddressBooks"
	childTagName = "AddressBook"
	nodeName = "AddressBookId"
	content = postData(url,formdata)
	addAddressBook = returnValue(content,tagName,childTagName,nodeName)	 
end function
public function addEmail(AddressBookID,emailList,idClient,APIkey) 
	url = "https://DomainName/v2/email/add.xml?"
	formdata = "IDClient="& idClient &"&APIKey="& APIkey &"&AddressBookId=" & AddressBookID & "&emailList=" & emailList & ""  
	content = postData(url,formdata) 
end function
public function addMessage(idClient,APIkey,message,subject) 
	url = "https://DomainName/v2/message/add.xml"
	formdata = "IDClient="& idClient &"&APIKey="& APIkey & "&Subject=" & subject & "&BodyHTML=" &  message &  "&Language=EN&" & "linkAlign=center&" & "LinkUp=1" & ""
	tagName = "Messages"
	childTagName = "Message"
	nodeName = "MessageId"
	content = postData(url,formdata)
	addMessage = returnValue2(content,childTagName,nodeName)
end function	
public function getIdExp(idClient,APIkey) 
	url = "https://DomainName/v2/senderEmail/list.xml?IDClient="& idClient &"&APIKey="& APIkey & ""
	tagName = "ExpEmails"	
	childTagName = "ExpEmail"
	nodeName = "ExpEmailId"
	content = getGet(url)
	getIdExp = returnValue(content,tagName,childTagName,nodeName)
end function	
public function addSend(idClient,APIkey,AddressBookID,MessageId,ExpID) 
	url = "https://DomainName/v2/send/add.xml"
	formdata = "IDClient="& idClient &"&APIKey=" & APIkey & "&IDAddressBook=" & AddressBookID & "&IDMessage="& MessageId &"&IDEmailExp=" &ExpID & "&Campaign=1"	
	content = postData(url,formdata)
end function
public function postData(url,formdata)
	Set oXmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
	lResolve =0
	lConnect =0
	lSend =0
	lReceive =0
	oXmlHttp.setOption 2, 13056
	oXmlHttp.open "POST",url, false
	oXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	oXmlhttp.setTimeouts lResolve, lConnect, lSend, lReceive
	oXmlHttp.send formdata
	responseTxt =Cstr(oXmlHttp.responseText)
	Set oXmlHttp = nothing	
	postData = responseTxt
end function		
public function returnValue(content,tagName,childTagName,nodeName)
	Set objxml = Server.CreateObject("Microsoft.XMLDOM")
	objxml.async = False
	objxml.loadXML content
	If objXML.parseError.errorCode <> 0 Then
		ReportErrorXML(objXML)
	End If		 
	Response.ContentType = "text/html"
	Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
	Response.CharSet = "UTF-8"	      
	For Each xmlProduct In objXML.getElementsByTagName(tagName)	  
		For Each xmladr In xmlProduct.getElementsByTagName(childTagName) 
			getContent = xmladr.selectSingleNode(nodeName).text					
		next
	Next  	  
	returnValue = getContent
end function
public function returnValue2(content,childTagName,nodeName)
	Set objxml = Server.CreateObject("Microsoft.XMLDOM")
	objxml.async = False
	objxml.loadXML content
	If objXML.parseError.errorCode <> 0 Then
		ReportErrorXML(objXML)
	End If
	Response.ContentType = "text/html"
	Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
	Response.CharSet = "UTF-8"	      
	For Each xmladr In objXML.getElementsByTagName(childTagName) 
		getContent = xmladr.selectSingleNode(nodeName).text					
	next
	returnValue2 = getContent	   
end function	
public function getGet(url)
	Set oXmlhttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
	lResolve =0
	lConnect =0
	lSend =0
	lReceive =0
	oXmlHttp.setOption 2, 13056
	oXmlHttp.open "GET", url, false	
	oXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	oXmlhttp.setTimeouts lResolve, lConnect, lSend, lReceive
	oXmlHttp.send
	responseTxt = Cstr(oXmlHttp.responseText)
	Set oXmlHttp = nothing
	getGet = responseTxt	 
end function		
public sub ReportErrorXML(objXML)
	strErrText=""		
	Set xPE = objXML.parseError
	With xPE
		strErrText = "Your XML Document failed to load" & _
		"due the following error." & vbCrLf & _
		"Error #: " & .errorCode & ": " & xPE.reason & _
		"Line #: " & .Line & vbCrLf & _
		"Line Position: " & .linepos & vbCrLf & _
		"Position In File: " & .filepos & vbCrLf & _
		"Source Text: " & .srcText & vbCrLf & _
		"Document URL: " & .url
	End With
	response.write strErrText
end sub
%>