Showing posts with label developer. Show all posts
Showing posts with label developer. Show all posts

Monday, March 05, 2012

Consuming the JangoMail API in ASP.Net

It's easy to start integrating the JangoMail API into your company's .Net software. Start by adding a service reference to your project. Right click on the project in the solution explorer, then click "Add a Service Reference". Under Address, enter http://api.jangomail.com/api.asmx?WSDL and click "Go". Then change the namespace to JangoMail and click "OK". This will add the files necessary to reference the JangoMail web service within your application or website. Then you can call all the JangoMail/JangoSMTP API methods from within your software.

In this two line example, a JangoMailSoapClient object is created, then used to invoke the method that gets a list of the email lists on your account. Download the source code for this example then start your own integration!

// first create the JangoMail soap client object
JangoMail.JangoMailSoapClient j = 
    new JangoMail.JangoMailSoapClient("JangoMailSoap");

// then call the getlist method and display the results
Result.InnerHtml = 
    j.Groups_GetList_String("Your JangoMail/JangoSMTP Username", 
                            "Your JangoMail/JangoSMTP Password", 
                            "<br/>", " - ", "");

Monday, February 27, 2012

Integrating the JangoMail API Into a Java Application

If you want to integrate JangoMail's web service into your company's existing Java software, this example will show you how to hit the ground running. This example relies on Java's built-in library for processing soap requests javax.xml.soap. Download the source code for this example here.

In the first part of this example, the SOAPMessage is created. In this case, we will call the Groups_GetList_String method, which will return a list of groups on your account. Make sure to set the SOAPAction header to indicate which method you want to call.

// create the connection
SOAPConnectionFactory soapConnFactory 
    = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnFactory.createConnection();

//Next, create the actual message/request
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
          
//Create objects for the request parts            
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
  
// set the SOAPAction Header to the desired request
MimeHeaders headers = message.getMimeHeaders();
headers.addHeader("SOAPAction", 
    "http://api.jangomail.com/Groups_GetList_String");
Next, the message is populated with our parameters and sent to the JangoMail servers.
// Populate the body of the request
// create the main element and namespace
SOAPElement bodyElement = body.addChildElement(
        envelope.createName("Groups_GetList_String", 
                            "", 
                            "http://api.jangomail.com/"));
   
// add the parameters
bodyElement.addChildElement("Username")
    .addTextNode("Your JangoMail/JangoSMTP Username");
bodyElement.addChildElement("Password")
    .addTextNode("Your JangoMail/JangoSMTP Password");
bodyElement.addChildElement("RowDelimiter").addTextNode("\n");
bodyElement.addChildElement("ColDelimiter").addTextNode(" - ");
bodyElement.addChildElement("TextQualifier").addTextNode("");
   
// save the message
message.saveChanges();
   
// Send the message and print the reply
// set the destination
String destination = "http://api.jangomail.com/api.asmx";
// send the message
SOAPMessage reply = connection.call(message, destination);
Finally, the response is received and printed.
//Check the output
System.out.println("\nRESPONSE:\n");

//Create the transformer
TransformerFactory transformerFactory 
    = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();

//Extract the content of the reply
Source sourceContent = reply.getSOAPPart().getContent();

//Set the output for the transformation
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
System.out.println();
Make sure to Download the complete source code for this example and populate it with the values from your JangoMail or JangoSMTP account.

Monday, February 20, 2012

Using the JangoMail API in PHP

Since PHP 5 provided developers with the SoapClient class, it's a snap to consume SOAP-enabled web services in a PHP script.

This example demonstrates how to connect to the JangoMail API in order to get the email lists on your account. Download the source code for this example, insert your own JangoMail credentials, and you're ready to start integrating the JangoMail API with your php website.

// create a SoapClient object for the jangomail aPI
$client = 
    new SoapClient("http://api.jangomail.com/api.asmx?WSDL");

// set the parameter array for the
// Groups_GetList_String method
$param=array(
 'Username'=>'Your JangoMail Username',
 'Password'=>'Your JangoMail Password',
 'RowDelimiter'=>'<br/>',
 'ColDelimiter'=>' - ',
 'TextQualifier'=>''
); 

// using the JangoMail API
// call the Groups_GetList_String method
$result = $client->Groups_GetList_String($param);

// print the groups that were returned
print($result->Groups_GetList_StringResult);