ColdFusion: Send A Letter With SendLetter()
Instructions
- Make sure your ColdFusion environment is ready and create a new CFM page.
- Copy the entire code below and paste the code in the CFM page.
- Replace the values of the cfset lines with your details:
- Replace MyUsername and MyPassword with your PostalMethods user details.
- Replace MyDescription with your own text to help you identify this letter in your activity log (optional).
- Replace absolutePathToFile 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.
- MyWorkMode determines if your letter will be sent as Production, Development or will use your user's default Work Mode setting. Read more about Production and Development Work Modes.
- Start your application. It will start, encode your document as Base64 and send a letter to the PostalMethods SendLetter 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/2009-02-26/PostalWS.asmx?WSDL'> <cfset MyUsername = 'MyUsername'> <cfset MyPassword = 'MyPassword'> <cfset MyDescription = 'Sending a letter using ColdFusion'> <!--- file to be posted; contents need to conform to requirements (you may use our templates: http://www.postalmethods.com/resources/developers-guide/templates) ---> <cfset absolutePathToFile = expandPath('MyFile.pdf')> <cfset MyWorkMode = 'Default'> <!--- /************* 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#"> <cfinvokeargument name="WorkMode" value="#MyWorkMode#"> </cfinvoke> <cfoutput> <cfif statusCode gt 0> Message submitted successfully with Letter ID <b>#statusCode#</b> <cfelse> Message submission failed on error <a href="http://www.postalmethods.com/resources/reference/status-codes">#statusCode#</a> </cfif> </cfoutput>

