CF: Send A Letter with SendLetterAndAddress()

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, method SendLetterAndAdress() will add the recipient's address to the document in such a way that it shows through the envelope window. You can use one of our Sample Letter Documents to avoid placing text in the address blocks.
  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. Run your application. It will send a letter to the SendLetterAndAddress() 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!

<!--- /************* 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')>
<cfset MyAttentionLine1 = 'AttentionLine1'>
<cfset MyAttentionLine2 = 'AttentionLine2'>
<cfset MyAttentionLine3 = 'AttentionLine3'>
<cfset MyCompany = 'My Company'>
<cfset MyAddress1 = 'My Address1'>
<cfset MyAddress2 = 'My Address2'>
<cfset MyCity = 'My City'>
<cfset MyState = 'My State'>
<cfset MyPostalCode = '12345'>
<cfset MyCountry = 'United States'>
 
<!--- /************* Settings  End ******************/ --->
 
 
<cffile action="readBinary" file="#absolutePathToFile#" variable="fileBinaryData">
 
 
<cfinvoke
	webservice="#webserviceUrl#"
	method="SendLetterAndAddress"
	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#">
		<cfinvokeargument name="AttentionLine1" value="#MyAttentionLine1#">
		<cfinvokeargument name="AttentionLine2" value="#MyAttentionLine2#">
		<cfinvokeargument name="AttentionLine3" value="#MyAttentionLine3#">
		<cfinvokeargument name="Company" value="#MyCompany#">
		<cfinvokeargument name="Address1" value="#MyAddress1#">
		<cfinvokeargument name="Address2" value="#MyAddress2#">
		<cfinvokeargument name="City" value="#MyCity#">
		<cfinvokeargument name="State" value="#MyState#">
		<cfinvokeargument name="PostalCode" value="#MyPostalCode#">
		<cfinvokeargument name="Country" value="#MyCountry#">
</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">#statusCode#</a>
</cfif>
</cfoutput>