C#

  1. using System;

  2. using System.IO;

  3. using System.Net;

  4. using System.Text;

  5. public class Program

  6. {

  7.     public static void Main()

  8.    {

  9.         // Create a request using a URL that can receive a post.

  10.         WebRequest request =WebRequest.Create("http://api.pepipost.com/api/web.send.rest");

  11.         // Set the Method property of the request to POST.

  12.         request.Method="POST";

  13.         // Create POST data and convert it to a byte array.

  14.         var postData ="api_key=YourApiKey";

  15.         postData +="&subject=TestMail";

  16.         postData +="&fromname=YourName";

  17.         postData +="&from=example@yourcompany.in";

  18.         postData +="&recipients=abc@yourcompany.in";

  19.         postData +="&content=The is the mail content to send";

  20.         byte[] byteArray =Encoding.UTF8.GetBytes(postData);

  21.         // Set the ContentType property of the WebRequest.

  22.         request.ContentType="application/x-www-form-urlencoded";

  23.         // Set the ContentLength property of the WebRequest.

  24.         request.ContentLength= byteArray.Length;

  25.         // Get the request stream.

  26.         Stream dataStream = request.GetRequestStream();

  27.         // Write the data to the request stream.

  28.         dataStream.Write(byteArray,0, byteArray.Length);

  29.         // Close the Stream object.

  30.         dataStream.Close();

  31.         // Get the response.

  32.         WebResponse response = request.GetResponse();

  33.         // Display the status.

  34.         Console.WriteLine(((HttpWebResponse)response).StatusDescription);

  35.         // Get the stream containing content returned by the server.

  36.         dataStream = response.GetResponseStream();

  37.         // Open the stream using a StreamReader for easy access.

  38.         StreamReader reader =new StreamReader(dataStream);

  39.         // Read the content.

  40.         string responseFromServer = reader.ReadToEnd();

  41.         // Display the content.

  42.         Console.WriteLine(responseFromServer);

  43.         // Clean up the streams.

  44.         reader.Close();

  45.         dataStream.Close();

  46.         response.Close();

  47.     }

  48. }