CF: Send A Letter With SendLetter()


  1. Make sure your ColdFusion environment is ready and create a new CFM page.
  2. Copy the entire code below and paste the code in the CFM page.
  3. Replace C:\MyFile.pdf with a path to your test PDF file. Remember, for method SendLetter() you must use a document where the recipient's address already appears so it will 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. Run your application. It will send a letter to the SendLetter() Web Service method. If the response is a positive number, you will be able to see your letter in the PostalMethods Control Panel.
  6. 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!

<!--- /************* Settings  Begin ****************/ --->
<cfset webserviceUrl = ''>
<cfset MyUsername = 'MyUsername'>
<cfset MyPassword = 'MyPassword'>
<cfset MyDescription = 'My first letter through'>
<!--- file to be posted; contents need to conform to requirements (address in proper address area) --->
<cfset absolutePathToFile = expandPath('MyFile.pdf')>
<!--- /************* Settings  End ******************/ --->
<cffile action="readBinary" file="#absolutePathToFile#" variable="fileBinaryData">
	returnVariable="statusCode" >
	    <cfinvokeargument name="Username" value="#MyUsername#">
		<cfinvokeargument name="Password" value="#MyPassword#">
		<cfinvokeargument name="MyDescription" value="#MyDescription#">
		<cfinvokeargument name="FileExtension" value="#ListLast(absolutePathToFile, '.')#">
		<cfinvokeargument name="FileBinaryData" value="#fileBinaryData#">
	statusCode is the (positive) transaction ID if successful, or a (negative) error number if unsuccessful
<cfif statusCode gt 0>
	Message submitted successfully with transaction ID <b>#statusCode#</b>
	Message submission failed on error <a href="">#status_code#</a>