C#: Send A Letter with SendLetterAndAddress()


  1. Create a new Console Application project and add a web reference
  2. Copy the entire code below, delete anything written in your application and paste the code there
  3. Replace C:\MyFile.pdf with a path to your test PDF file. Remember, method SendLetterAndAdress will add the recipient's address so it would show through the envelope window. You can use one of our Sample Letter Documents.
  4. Replace MyUsername and MyPassword with your PostalMethods user details
  5. Replace all the address parameters with real address values. Leave an empty string ("") where no value is needed.
  6. Start your application. It will start and send a letter to the PostalMethods SendLetterAndAddress Web Service method. If the response is a positive number, you will be able to see your letter in the PostalMethods Control Panel.
    If the response is negative number, check the Web Service Status Codes section.

That's it - you have successfully sent a letter to PostalMethods. Congratulations.

using System.IO;
class Module1
    public void Main()
        com.postalmethods.api.PostalWSSimple objPM = new com.postalmethods.api.PostalWSSimple();
        long lngResult;
        // Read your binary document. In this example: C:\MyFile.pdf
        FileStream objFR;
        objFR = new FileStream("C:\\MyFile.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        byte[] B = new byte[objFR.Length];
        objFR.Read(B, 0, B.Length);
        objFR = null;
        // Invoke the SendLetter method
        lngResult = objPM.SendLetterAndAddress(
        // Check response status
        if (lngResult > 0)
            // A positive value means the message was successfully queued for processing.
            // The PostalMethods Letter ID is returned.
            Console.WriteLine("LetterID is: " + lngResult);
            // A negative value means an error occurred.
            // See the PostalMethods Status Codes: http://www.postalmethods.com/statuscodes.
            Console.WriteLine("Error is:" + lngResult);
        // In debug mode, the following lines prevent your console application from closing automatically upon termination
        Console.WriteLine("Hit ENTER to terminate application");