ASP: Send A Letter with SendLetterAndAddress()


  1. Create a new ASP page.
  2. Copy the entire code below and paste the code inside the ASP page.
  3. Replace C:\MyFile.pdf with a path to your test PDF file. Remember, method SendLetterAndAdressV2 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 SendLetterAndAddressV2 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.

' This asp script demonstrates how to send a binary file 
' (such as .PDF, .DOC) from an ASP script, using MS SOAP 3.0
' and the SendLetterAndAddressV2 method within PostalMethods. As asp has no 
' built in provisions to reading binary files, we use an ADODB.Stream 
' object to do so.
Option Explicit 
Const Filename = "C:\MyFile.pdf"
Const MyUsername = "MyUsername"
Const MyPassword = "MyPassword"
Const Description = "Send a letter using ASP"
Const AttentionLine1 = "Mr. Danny Kay"
Const AttentionLine2 = "Director, Dancing Dept."
Const CompanyName = "Comedy Makers"
Const AddressLine1 = "1234 Main ST."
Const AddressLine2 = "1st FL."
Const City = "Brooklyn"
Const State = "NY"
Const PostalCodeZIP = "11201"
Const Country = "USA"
Dim objSoap, lngResult
Dim B
' Read your binary document.
B = ReadBinaryFile(Filename)
'Create the SoapClient object    'MS SOAP v3.0
Set objSoap = Server.CreateObject("MSSOAP.SOAPClient30")
'Set to True when an Active Server Pages (ASP) application or an ISAPI DLL uses the SoapClient object.
objSoap.ClientProperty("ServerHTTPRequest") = True 
'Initializes the SoapClient object. ASP initializes the WSDL on each call. 
'For better performance, you may download the WSDL locally as an XML and refer to the local file.
'Set to True when a proxy server is to be detected automatically
objSoap.ConnectorProperty("EnableAutoProxy") = True
' Invoke the SendLetterAndAddress() method
lngResult = objSoap.SendLetterAndAddress( _
            MyUsername, _
            MyPassword, _
            Description, _
            "pdf", _
            B, _
            AttentionLine1, _
            AttentionLine2, _
            CompanyName, _
            AddressLine1, _
            AddressLine2, _
            City, _
            State, _
            PostalCodeZIP, _
If CLng(lngResult) > 0 Then 
	WriteLine("LetterID is: " & lngResult)
    WriteLine("Error is:" & lngResult)
End If
'    Utility methods
Function ReadBinaryFile(FileName)
  Const adTypeBinary = 1
  'Create Stream object
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")
  'Specify stream type - we want To get binary data.
  BinaryStream.Type = adTypeBinary
  'Open the stream
  'Load the file data from disk To stream object
  BinaryStream.LoadFromFile FileName
  'Open the stream And get binary data from the object
  ReadBinaryFile = BinaryStream.Read
  'Clean up
  Set BinaryStream = Nothing
End Function
Sub WriteLine(T)
	Response.Write T & "<BR>"
End Sub
'Note: If this script is running from behind a proxy using MS SOAP v.3, you can use one of the two following options:
'Option 1 - Use automatic detection by:
'    objSoap.ConnectorProperty("EnableAutoProxy") = True
'Option 2 - Specify a proxy server:
'     objSoap.ConnectorProperty("ProxyServer") = ""
'and optionally, if the proxy server is password-protected specify:
'     objSoap.ConnectorProperty("ProxyUser") = "Proxy Username"
'     objSoap.ConnectorProperty("ProxyPassword") = "Proxy Password"

Send Letters
Securely + Reliably
Send letters securely and reliably from any business application. Use for invoices, quotes, and other important business communications. Enjoy special web-form to postal features and instant notifications.
Simple Process
Easy as 1-2-3
Experience the ease of our streamlined process - developed for efficiency! You submit your document by email or API. We automatically print, collate, insert, and stamp your letter. Your letter is delivered via standard postal service.
Pay As You Go
No Fuss. No Obligations.
Register for free with no obligations! Evaluate the service as long as you need. Once you are ready, set up our user-friendly pay-as-you option to use our service. No fuss. No on-going commitment. Just plain easy!