Ruby: Send A Letter With SendLetterAndAddress()

This sample demonstrates how to send a letter through PostalMethods using the Address Outside method.

This code sends the selected document to PostalMethods:

  1. Prepare a document (any one of the supported file types), of which the first page of the first document needs to be properly-formatted so a whitespace is left in order to stamp the recipient address.
  2. Replace MyUsername and MyPassword with your PostalMethods user details.
  3. Replace address fields with the recipient address details. Additional fields are available.
  4. Replace /path/to/document.pdf with the full path to your document.
  5. Execute this code. It will initiate and send a letter to the PostalMethods SendLetterAndAddress Web Service method. If the response is a positive number, the request was successful and the number is the unique ID or your letter. You will be able to see your letter in the PostalMethods Control Panel.
    If the response is negative number, the request was unsuccessful. Check the Web Service Status Codes section.
#!/usr/bin/env ruby 
require 'rubygems'
require 'postalmethods'
options = {:username => 'MyUsername', :password => 'MyPassword'}
address = {:AttentionLine1 => "The White House", :Address1 => "1600 Pennsylvania Avenue NW", :City => "Washington", :State => "DC", :PostalCode => 
"20500", :Country => "USA"}
client =
document = open('/path/to/document.pdf')
retvalue = client.send_letter_with_address(document, "description",