Ruby: Send A Letter With SendLetter()

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

This code sends the selected document to PostalMethods:

  1. Prepare a document (either pdf, doc, docx or html), of which the first page of the first document needs to be properly-formatted to align to a window envelope.
  2. Replace MyUsername and MyPassword with your PostalMethods user details
  3. Replace /path/to/document.pdf with the full path to your document
  4. Execute this code. It will initiate and send a letter to the PostalMethods SendLetter 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'}
client =
document = open('/path/to/document.pdf')
retvalue = client.send_letter(document, "description")