CF: Send A Letter With SendLetter()

Instructions

  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 = 'https://api.postalmethods.com/PostalWS.asmx?WSDL'>
<cfset MyUsername = 'MyUsername'>
<cfset MyPassword = 'MyPassword'>
<cfset MyDescription = 'My first letter through PostalMethods.com'>
<!--- 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">
 
 
<cfinvoke
	webservice="#webserviceUrl#"
	method="SendLetter"
	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#">
</cfinvoke>
 
 
<!---
	statusCode is the (positive) transaction ID if successful, or a (negative) error number if unsuccessful
--->
<cfoutput>
<cfif statusCode gt 0>
	Message submitted successfully with transaction ID <b>#statusCode#</b>
<cfelse>
	Message submission failed on error <a href="http://www.postalmethods.com/statuscodes#webservice">#status_code#</a>
</cfif>
</cfoutput>