JangoMail Tutorial API
JangoMail Tutorial API
Overview:
Tutorial
The JangoMail Application Programming Interface (API): Using the JangoMail Web Service
The JangoMail API is a remotely accessible web service that can be interacted with through several methods, all of which are available across the Internet. It allows you to get data into and out of your JangoMail account programmatically and without visiting www.jangomail.com.
https://api.jangomail.com. For a complete list of methods and their parameters see the class reference below.
Code example in ASP/VBScript to add an email address to your unsubscribe list via HTTP GET: dim xml, url, RetVal, BaseURL, CommandName, Username, Password Set xml = Server.CreateObject("Microsoft.XMLHTTP") BaseURL = "http://api.jangomail.com/api.asmx/" Username = "Stephen" Password = "AlleyCat" CommandName = "AddUnsubscribe" url = BaseURL & CommandName url = url & "?Username=" & Server.URLEncode(Username) url = url & "&Password=" & server.URLEncode(Password)
JangoMail Tutorial Page 2 of 8 Evaluating Customers: http://www.jangomail.com/Contact or 1-888-465-2646 Current Customers: https://www.jangomail.com/Support or 1-888-709-4099
url = url & "&EmailAddress=" & server.URLEncode("[email protected]") xml.Open "GET", url, False xml.Send RetVal = xml.ResponseText Set xml = nothing 'At this point RetVal is the response from the webservice if left(RetVal, 5) = "<?xml" then 'Successful call RetVal = mid(RetVal, instr(instr(RetVal, "<string"), RetVal, ">")+1) RetVal = left(RetVal, len(RetVal) - 9) 'chop off trailer </string> else 'errored Err.Raise 3, "JMSClient", left(RetVal, instr(RetVal, vbcrlf)) end if Same example in PERL: require LWP::UserAgent; $ua = LWP::UserAgent->new; $MethodName = "AddUnsubscribe"; $Username = "demo"; $Password = "demo123"; $EmailAddress = "[email protected]"; $request = HTTP::Request->new(GET => "http://api.jangomail.com/api.asmx/$MethodName?Username=$Username&Password =$Password&EmailAddress=$EmailAddress"); $response = $ua->request($request); print $response->content;
Accessing via HTTP POST: Methods can be accessed by performing an HTTP POST request to a URL in this format: http://api.jangomail.com/api.asmx/[MethodName] and posting method parameters in this format: Username=[Username]&Password=[Password] &[Additional_Parameter1]=[Value1]& &[Additional_Parameter2]=[Value2]& where MethodName is the function you want to perform, Username is your JangoMail account username, Password is your JangoMail account password, and Additional_Parameter1/Value1, Additional_Parameter2/Value2, etc. are additional parameters required by the method. For example, the AddBounce method requires an email address as an additional parameter. POST requests can performed using your web browser or through any platform that can send an HTTP POST request such as ASP, PERL or Java. Responses to a POST request are in identical format to the response from a GET request. Code example in ASP/VBScript to add an email address to your unsubscribe list via HTTP POST:
Set xml = Server.CreateObject("Microsoft.XMLHTTP") BaseURL = "http://api.jangomail.com/api.asmx/" Username = "Stephen" Password = "AlleyCat" CommandName = "AddUnsubscribe" url = BaseURL & CommandName params = params & "Username=" & Server.URLEncode(Username) params = params & "&Password=" & server.URLEncode(Password) params = params & "&EmailAddress=" & server.URLEncode("[email protected]") xml.Open "POST", url, False xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xml.Send params RetVal = xml.ResponseText Set xml = nothing 'At this point RetVal is the response from the web service if left(RetVal, 5) = "<?xml" then 'Successful call RetVal = mid(RetVal, instr(instr(RetVal, "<string"), RetVal, ">")+1) RetVal = left(RetVal, len(RetVal) - 9) 'Chop off trailer </string> else 'Errored Err.Raise 3, "JangoMailWebService", left(RetVal, instr(RetVal, vbcrlf)) end if Same example in PERL: require LWP::UserAgent; $ua = LWP::UserAgent->new; $MethodName = "AddUnsubscribe"; $Username = "Stephen"; $Password = "AlleyCat"; $EmailAddress = "[email protected]"; my $request = HTTP::Request->new(POST => "http://api.jangomail.com/api.asmx/$MethodName"); $request->content_type("application/x-www-form-urlencoded"); $request>content("Username=$Username&Password=$Password&EmailAddress=$EmailAddress "); $response = $ua->request($request); print $response->content;
Accessing via Simple Object Access Protocol: The JangoMail Web Service is also fully compliant with the Simple Object Access Protocol as described by the World Wide Web Consortium (W3C) and is the preferred method for accessing JangoMail data. SOAP is a simple XML based protocol to let applications exchange information over HTTP. The main advantages of SOAP compared to other standards are: SOAP is designed to communicate via Internet SOAP is platform independent
JangoMail Tutorial Page 4 of 8 Evaluating Customers: http://www.jangomail.com/Contact or 1-888-465-2646 Current Customers: https://www.jangomail.com/Support or 1-888-709-4099
is language independent is based on XML is simple and extensible allows you to get around firewalls will be developed as a W3C standard
For more information on SOAP please refer to: http://www.w3schools.com/soap/soap_intro.asp http://www.cs.fsu.edu/~engelen/soap.html (gSOAP, C++ toolkit) http://www.perl.com/pub/a/2001/01/soap.html (Perl SOAP module) http://www.w3.org/TR/soap/ (W3C specification)
The JangoMail Web Service can be accessed at http://api.jangomail.com/api.asmx or securely at https://api.jangomail.com/api.asmx. If you are using Visual Studio .NET, the associated classes for calling the SOAP interface can be generated manually using wsdl.exe with the following call: wsdl.exe /language:cs /out:JangoMailServiceProxy.csc http://api.jangomail.com/api.asmx?WSDL This will create JangoMailServiceProxy.csc which you can include in a Visual Studio project, or you can generate a DLL to use with an ASP.NET application with the following command: csc.exe /t:library /out:JangoMailServiceProxy.dll JangoMailServiceProxy.csc This will compile JangoMailServiceProxy.csc to JangoMailServiceProxy.dll which you can reference in a Visual Studio project, or place in your webservers /bin directory for use with an ASP.NET application. Sample call from a C# application: JangoMail j = new JangoMail(); try { j.AddUnsubscribe("Stephen", "AlleyCat", "[email protected]"); } catch(Exception ex) { Console.WriteLine(ex.Message); } SOAP requests can also be sent manually if formatted correctly and the correct HTTP headers are sent with the request. A SOAP request to the AddUnsubscribe method has the following format: POST /api.asmx HTTP/1.1 Host: api.jangomail.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://api.jangomail.com/AddUnsubscribe" <?xml version="1.0" encoding="utf-8"?>
JangoMail Tutorial Page 5 of 8 Evaluating Customers: http://www.jangomail.com/Contact or 1-888-465-2646 Current Customers: https://www.jangomail.com/Support or 1-888-709-4099
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <AddUnsubscribe xmlns="http://api.jangomail.com/"> <Username>string</Username> <Password>string</Password> <EmailAddress>string</EmailAddress> </AddUnsubscribe> </soap:Body> </soap:Envelope>
Here is a code sample in classic ASP that can create and submit a SOAP request: BaseURL = "http://api.jangomail.com/api.asmx" SoapAction = "http://api.jangomail.com/AddUnsubscribe" Username = "Stephen" Password = "AlleyCat" EmailAddress = "[email protected]" Req = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf Req = Req & "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchemainstance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & vbCrLf Req = Req & "<soap:Body>" & vbCrLf Req = Req & "<AddUnsubscribe xmlns=""http://api.jangomail.com/"">" & vbCrLf Req Req Req Req Req Req = = = = = = Req Req Req Req Req Req & & & & & & "<Username>" & Username & "</Username>" & vbCrLf "<Password>" & Password & "</Password>" & vbCrLf "<EmailAddress>" & EmailAddress & "</EmailAddress>" & vbCrLf "</AddUnsubscribe>" & vbCrLf "</soap:Body>" & vbCrLf "</soap:Envelope>" & vbCrLf
dim xml, url, RetVal Set xml = Server.CreateObject("Microsoft.XMLHTTP") xml.Open "POST", BaseURL, False xml.setRequestHeader "Content-Type", "text/xml; charset=utf-8" xml.setRequestHeader "SOAPAction", SoapAction xml.Send Req RetVal = xml.ResponseText Set xml = nothing response.Write(RetVal)
JangoMail Tutorial Page 6 of 8 Evaluating Customers: http://www.jangomail.com/Contact or 1-888-465-2646 Current Customers: https://www.jangomail.com/Support or 1-888-709-4099
JangoMail j = new JangoMail(); string ResultString = ; try { ResultString = j.AddUnsubscribe("test", "pass", "[email protected]"); } catch(Exception ex) { Console.WriteLine(ex.Message); } if (ResultString=0\nSUCCESS) { Console.WriteLine(The unsubscribe operation was successful.); } In this code sample, if the username/password combination of test or pass is invalid, then the execution of the code will be passed to the catch block, and an appropriate error will be written to the console. Similarly if the email address is an invalid email address, the catch block would write a friendly error message to the console. If the method is successful, then the ResultString variable is set to 0\nSUCCESS and the code would write out the sentence The unsubscribe operation was successful. to the console. All methods will only return their true return type if the method executes successfully and all input parameters are valid. If a method is unable to execute successfully for any reason, an exception is thrown instead of returning the expected object type. Heres an example where the API is called using an HTTP POST rather than SOAP in Visual Basic: Dim xml, RetVal, Username, Password Set xml = CreateObject("Microsoft.XMLHTTP") Username = "Stephen" Password = "AlleyCat" params = params & "Username=" & Username
JangoMail Tutorial Page 7 of 8 Evaluating Customers: http://www.jangomail.com/Contact or 1-888-465-2646 Current Customers: https://www.jangomail.com/Support or 1-888-709-4099
params = params & "&Password=" & Password params = params & "&EmailAddress=" & "[email protected]" xml.Open "POST", "http://api.jangomail.com/api.asmx/AddUnsubscribe", False xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" xml.Send params RetVal = xml.ResponseText Set xml = Nothing 'At this point RetVal is the response from the webservice If Left(RetVal, 5) = "<?xml" Then 'Successful call MsgBox (RetVal) Else 'Errored MsgBox (RetVal) End If If the username/password combination is invalid, then RetVal would be set to: Web Service Exception LoginFaledException: Username and password do not match. If the method does execute successfully, then RetVal would be set to: <?xml version="1.0" encoding="utf-8"?> <string xmlns="http://api.jangomail.com/">0 SUCCESS</string>
JangoMail Tutorial Page 8 of 8 Evaluating Customers: http://www.jangomail.com/Contact or 1-888-465-2646 Current Customers: https://www.jangomail.com/Support or 1-888-709-4099