VB.NET: Send A Letter with SendLetterAndAddress()
- Create a new Console Application project and add a web reference
- Copy the entire code below, delete anything written in your application and paste the code there
- 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.
- Replace MyUsername and MyPassword with your PostalMethods user details
- Replace all the address parameters with real address values. Leave an empty string ("") where no value is needed.
- 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.
Imports System.IO Module Module1 Sub Main() Dim objPM As New com.postalmethods.api.PostalWSSimple() Dim lngResult As Long ' ' Read your binary document. In this example: C:\MyFile.pdf ' Dim objFR As FileStream objFR = New FileStream("C:\MyFile.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite) Dim B(objFR.Length - 1) As Byte objFR.Read(B, 0, B.Length) objFR.Close() objFR = Nothing ' ' Invoke the SendLetter method ' lngResult = objPM.SendLetterAndAddress( _ "MyUsername", _ "MyPassword", _ "ThisIsMyDescription", _ "pdf", _ B, _ "AttentionLine1", _ "AttentionLine2", _ "AttentionLine3", _ "CompanyName", _ "AddressLine1", _ "AddressLine2", _ "City", _ "State", _ "PostalCodeZIP", _ "Country") ' ' Check response status ' If lngResult > 0 Then ' ' A positive value means the message was successfully queued for processing. ' The PostalMethods Letter ID is returned. ' Console.WriteLine("LetterID is: " & lngResult) Else ' ' A negative value means an error occurred. ' See the PostalMethods Status Codes: http://www.postalmethods.com/statuscodes#webservice. ' Console.WriteLine("Error is:" & lngResult) End If ' In debug mode, the following lines prevent your console application from closing automatically upon termination Console.WriteLine("Hit ENTER to terminate application") Console.ReadLine() End Sub End Module