Java

  1. import java.io.BufferedReader;

  2. import java.io.DataOutputStream;

  3. import java.io.InputStreamReader;

  4. import java.net.HttpURLConnection;

  5. import java.net.URL;

  6. import java.net.URLEncoder;

  7. publicclassJavasample{

  8. publicstaticvoid main(String[] args){

  9.     String to ="example@pepipost.com";

  10.     String apikey ="YourApiKey";

  11.     Stringfrom="example@pepipost.com";

  12.     String fromname ="ABC";

  13.     String content ="This is Mail Content";

  14.     String subject ="Test Mail";

  15.     String myurl ="http://api.pepipost.com/api/web.send.rest";

  16.     try{

  17.         String postData ="api_key="+apikey;

  18.         postData +="&subject="+URLEncoder.encode(subject,"UTF-8");

  19.         postData +="&fromname="+URLEncoder.encode(fromname,"UTF-8");

  20.         postData +="&from="+from;

  21.         postData +="&recipients="+to;

  22.         postData +="&content="+URLEncoder.encode(content,"UTF-8");

  23.     String urlParameters = postData;

  24.         URL url =new URL(myurl);

  25.     HttpURLConnection connection;

  26.         connection =(HttpURLConnection)url.openConnection();

  27.         connection.setRequestMethod("POST");

  28.         connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

  29.         connection.setRequestProperty("Content-Length",""+Integer.toString(urlParameters.getBytes().length));

  30.         connection.setRequestProperty("Content-Language","en-US");

  31.         connection.setUseCaches (false);

  32.         connection.setDoInput(true);

  33.         connection.setDoOutput(true);

  34.     DataOutputStream wr =newDataOutputStream(connection.getOutputStream ());

  35.         wr.writeBytes (urlParameters);

  36.         wr.flush ();

  37.         wr.close ();

  38.      BufferedReaderin=newBufferedReader(newInputStreamReader(connection.getInputStream()));

  39.     String inputLine;

  40.     StringBuffer response =newStringBuffer();

  41.     while((inputLine =in.readLine())!=null){

  42.        response.append(inputLine);

  43.     }

  44.     in.close();

  45.     System.out.println(response.toString());

  46.     }

  47.     catch(Exception e){

  48.           e.printStackTrace();

  49.      }

  50.   }

  51. }