Smartermail API wrapper for coldfusion - version 1.1.1

smartermail iconFor all of you who have Smartermail as their mailserver software, I just made your life a bit easier!
You probably already know that it is not possible inside of smartermail, to change user settings for all existing customers in one time? You can change the Defaults for new users, but existing, nehh.
Since I needed to do some global changes for a few hundred accounts, I decided to check out the Smartermail API. And what began as a simple task, turned into my newest opensource Coldfusion project: the Smartermail API wrapper for coldfusion, complete with a UI for everyone!

The main file that cfml developers will use is smartermail.cfc , which does the actuall call to the webservice.
All other people (also non-coldfusion-people) can use the API wrapper UI which I also built.

Versions

28 march 2010: Version 1.1
Changes in the smartermail API wrapper code, to make it CF7/8 compatible. (it used to be Railo + CF9 only)

9 may 2010: Version 1.1.1
The api wrapper now uses the xmlFormat() function for all values in the soap call. The smartermail api wrapper UI now shows a textarea when the field for an api function has 'description' in it's name. Also, all form values are now escaped with htmleditformat() when the form is shown again after submit. Also, some minor text/layout change.

Download the code

WSDL? No, just cfhttp ;-)

One of the biggest irritations with webservices is the wsdl itself, and the flunky way coldfusion handles it. For me, the simpler you can do it, the better. Web services are just a way of communication: I send an xml package with a question inside, and I get an xml package returned with the answer. That's it.
So, I decided to not use <cfinvoke>, but just <cfhttp>:

<cfhttp method="post" url="#this.serverURL#/Services/#arguments.page#.asmx" throwonerror="yes" result="cfhttpReturn_struct">
    <cfhttpparam type="header" name="Content-Type" value="application/soap+xml" />
    <cfhttpparam type="body" value="#soapBody#" />
</cfhttp>

The UI

As you can see in the example pages, all the methods are there, complete with the documentation and an example of the soap xml which is used. If you just want to use the UI, then just don't care about the xml; it's all done for you. Just fill in the displayed form, and you're fine!

For starters, you have to login with your server credentials. After that, a check is done to see if the credentials are correct.
Then, you are ready to go!

All of the options can also be done in your smartermail administrator, but I've made a few extras...
You can manage the settings for multiple email addresses in one time, and even for multiple domains in one time. If, for example, you want to change the mailbox size of 200 users, you only have to do one call! (hmm, wasn't that the thing I originally just needed to do?)

How to use the API wrapper yourself.

First, create the smartermail-object with the admin details:

<cfset variables.smartermail_obj = createObject("component", "Smartermail").init(serverURL="http://webmail.yourserver.com", wsUsername="your admin username", wsPassword="your admin password") />

Then, you can call any function you like, like this:

<cfset return_xml = variables.smartermail_obj.callWs(page='svcDomainAdmin', method='GetAllDomains') />

In case you need to give extra arguments to the page you are calling, you supply the extra argument 'args', like this:

<cfset extraArguments_struct = structNew() />
<cfset extraArguments_struct['DomainName'] = "somedomain.com" />
<cfset return_xml = variables.smartermail_obj.callWs(page='svcUserAdmin', method='GetUsers', args=extraArguments_struct) />

If you want to find out which arguments you need, then just check the UI test pages!

In the example pages I created an option to manage the settings for multiple domains and email addresses in one time. This is actually pretty simple to do, since you only have to loop over a list, like this:

<cfset emailList = "email1@domain.com,email2@domain.com,email9@otherdomain.com" />
<cfloop list="#emailList#" index="email">
	<cfset form.EmailAddress = email />
	<cfset extraArguments_struct = structNew() />
	<cfset extraArguments_struct['EmailAddress'] = email />
	<cfset return_xml = variables.smartermail_obj.callWs(page="svcUserAdmin", method="GetUser", args=extraArguments_struct) />
	<!--- you might want to do something with the xml you retrieved here --->
</cfloop>

When one of the parameters has multiple values (i.e. 3 mail addresses for 1 alias), then you need to send the 3 mailaddresses as an CRLF-delimited list, like this:

<cfset extraArguments_struct = structNew() />
<cfset extraArguments_struct['DomainName'] = "domain.com" />
<cfset extraArguments_struct['AliasName'] = "allclients" />
<cfset extraArguments_struct['Addresses'] = "info@client1.com
info@client2.com
peter@client3.com" />
<cfset return_xml = variables.smartermail_obj.callWs(page="svcAliasAdmin", method="AddAlias", args=extraArguments_struct) />

Usefull?

I hope you like and use the code! If so, leave me a comment; I'd like it!

Better yet, if you need a coldfusion (or Railo!) developer, hire me!

del.icio.us Digg StumbleUpon Facebook Technorati Fav reddit Google Bookmarks
| Viewed 666 times
  1. Ricardo

    #1 by Ricardo - January 13, 2010 at 5:27 PM

    Hi Paul, I downloaded the package and tried to run, but it seems to miss a folder required by the Application.cfm, /wddx/methodArguments.wddx Can you send that to me ? Thanks.
  2. Paul Klinkenberg

    #2 by Paul Klinkenberg - January 13, 2010 at 5:44 PM

    Hi Ricardo, well, that's just got to mean you're the first one who wanted to use it ;-) I updated the zip file to include *all* the files: http://www.coldfusiondeveloper.nl/smartermail-api-wrapper/Smartermail-API-wrapper-coldfusion.zip Let me know if you have any questions! Regards, Paul
  3. Ricardo

    #3 by Ricardo - January 13, 2010 at 5:51 PM

    Paul, Thanks for your attention. I'm hoping to successfully access our mail server though the API, since the tests I've done by reading SmarteTools documents were a failure. I'll keep you posted of my results. By the way, do you want a free email account at our domain CFDEVELOPERS.NET ? Just let me know which username you want. Best regards, Ricardo
  4. Paul Klinkenberg

    #4 by Paul Klinkenberg - January 13, 2010 at 6:08 PM

    Hi Ricardo, Thanks for the offer, but I am already using too much email addresses :) (and paul@coldfusiondeveloper.nl is also quite catchy I think ;) Hope to hear about your results! Paul
  5. Ricardo

    #5 by Ricardo - January 15, 2010 at 6:06 PM

    @Paul, I am using your API successfully to check email accounts, get a list of users and aliases, add new user and add new alias. One thing that I need to know is how to pass multiple addresses for an alias. When I send just one address in "params.Addresses" it works fine, but if I send multiple addresses in a comma or pipe delimited list, it creates the alias with none addresses. I tried to send them as an array, then I got an error from your API. Any light on that ? Thanks.
  6. Paul Klinkenberg

    #6 by Paul Klinkenberg - January 15, 2010 at 6:31 PM

    You can add multiple '[string]email[/string]' tags inside the Addresses tag. You could've also found out by using the API UI btw :) http://www.coldfusiondeveloper.nl/smartermail-api-wrapper/index.cfm?method=AddAlias&page=svcAliasAdmin Good luck, Paul
  7. Ricardo

    #7 by Ricardo - January 15, 2010 at 7:20 PM

    Paul, Here is the deal, I receive the operations request from a PHP page in a XML-RPC package, which I transform into ColdFusion structure, then do my validations, modify some parameters and then I call your API which converts my parameters into a SOAP and communicates with SmarterMail. I found out that if I send the multiple addresses in my parameter "params.Addresses" as a CR-LF delimited list, IT WORKS!. Then I transform your results back into XML-RPC for the PHP page to understand it. I'm very happy with your API, it solved our big problem here. I will blog about it in the near future and link to your blog. Thanks for your good job.
  8. Paul Klinkenberg

    #8 by Paul Klinkenberg - January 17, 2010 at 3:34 PM

    Yes that's true, if you made your own implementation based on the cfc, then you need to delimite the list by line-breaks (\r and/or \n) Well, hope to see your blog post in the near future!
  9. Ty Whalin

    #9 by Ty Whalin - March 10, 2010 at 3:32 AM

    Okay, I'm going to spend some time looking at the wrapper which may come to use for me since all the site I host use Smarter Mail. But I got one for ya that I can't seem to get right just yet. Do you possibly have a simple solution for checking domain name availability? I have spent several days trying to make the code work but no luck yet. I've done extensive searching for this type of process with CF but not much has came up. As a matter of fact that's how I found your wrapper. Is to complex for me at the moment buy I'm gaining CF speed. THX in advance.
  10. Paul Klinkenberg

    #10 by Paul Klinkenberg - March 10, 2010 at 11:15 AM

    Hi Ty, I don't know what your search words were, but when I do a google search, this is the first result: http://www.bennadel.com/blog/1410-Ask-Ben-Checking-Domain-Name-Availability-Using-ColdFusion.htm Good luck!
  11. Ty Whalin

    #11 by Ty Whalin - March 11, 2010 at 3:59 PM

    That's the only one I could find for checking domain name availability. I've tried to get that to work but it keeps returning domain name available no matter what site I search for availability. What I'm trying to do is run a CGI_SCRIPT_NAME on my form and then output the information on my page instead of using the hardcoded url's Ben supplied. At first there was an error with the
     part in the MatchNoCase Expression and was getting a position not found error. After I got past that catch error it continues to say every name is available.
    Thinking it might be something to do with the way my form submits. Set to get method by the way. If you've ever used beens code and got it to work let me know.
    THX for your time.
  12. Paul Klinkenberg

    #12 by Paul Klinkenberg - March 11, 2010 at 5:13 PM

    Did you check the url that is used to get the domain check report? It is http://reports.internic.net/cgi/whois On that page, it says "Search (.aero, .arpa, .asia, .biz, .cat, .com, .coop, .edu, .info, .int, .jobs, .mobi, .museum, .name, .net, .org, .pro, or .travel)" I guess you're trying to check another extension, which is simply not supported. If you check .com domains, it will work; I tested.
  13. Jack

    #13 by Jack - March 26, 2010 at 7:12 AM

    Hi Paul, I have installed your zip and I am unable to view the index.cfm in my browser. The error is "Template Exception - in SMadminWrapper\index.cfm : line 83 Missing argument name.'" I have not changed anything or added any code yet... Just tring to get it to load right now. Could you help.
  14. Paul Klinkenberg

    #14 by Paul Klinkenberg - March 26, 2010 at 7:50 AM

    Hi Jack, could you provide some more details? What Coldfusion version are you running? Or better: can you pass me a link to your install? You can mail it if you want, to paul at ongevraagdadvies.nl.
  15. Jack

    #15 by Jack - March 29, 2010 at 4:58 PM

    Thank you Paul for the updated backward compatible ver 1.1. I installed it and there does not seem to be any issues on CF 8 or CF 9 Enterprise Servers (not running Railo). I will continue testing each method and let you know if I find any issues.
  16. Sarah

    #16 by Sarah - April 28, 2010 at 10:44 AM

    Hi, is this a way to send paragraphed text, ie. each line would be a list item? is there a different way to send paragraphed text that would usually be wrapped in when making say a SOAP call?
  17. Pardeep

    #17 by Pardeep - May 2, 2010 at 9:02 PM

    @Paul Klinkenberg This API is frickin awesome time saver man. Thanks so much:)
  18. Paul Klinkenberg

    #18 by Paul Klinkenberg - May 5, 2010 at 11:56 PM

    @pardeep thanks :-) @Sarah: I have made a new version of the cfc and the ui files, with which you can use paragraphed text (html text and/or line breaks). You can only find it in the svn browser, since I have had no time to make an official new release. Good luck with it!
  19. paul

    #19 by paul - May 9, 2010 at 9:31 PM

    Hi, I'm new to this - I'm trying to use the API to update a single email address Can you give me a sample cfinvoke and relevant arguments that are needed to get going on this? Thanks Paul
  20. Paul Klinkenberg

    #20 by Paul Klinkenberg - May 9, 2010 at 9:49 PM

    Hi Paul, so which part of the "How to use the API wrapper yourself." section is unclear? Do you only need the "relevant arguments", or is anything else unclear as well? The arguments, you can find when looking at the UI. You probably need UpdateUser in the svcUserAdmin: http://www.coldfusiondeveloper.nl/smartermail-api-wrapper/index.cfm?method=UpdateUser&page=svcUserAdmin Hope it works for you! Paul
  21. Grant B.

    #21 by Grant B. - May 12, 2010 at 7:49 PM

    What versions of SmarterMail is this for? I am trying to use it with SM 4.3 but the web service does not seem to recognize the 'disablegreylisting' key for the SetRequestedUserSettings function in svcUserAdmin. I even tried GetRequestedUserSettings but smartermail simply ignores the 'disablegreylisting' value. It returns other string/value pairs but not 'disablegreylisting' ... actually also does the same with 'lockpassword'. Any idea where I would find a list of the keys for version 4.3?
  22. Paul Klinkenberg

    #22 by Paul Klinkenberg - May 13, 2010 at 11:31 AM

    Hi Grant, I have only tested this on the most recent smartermail, 6.5? You can find instructions for your own api interface by going to those pages... By default it shows you the soap xml. The urls are shown when you use the UI available from this post. Good luck!
(will not be published)
Leave this field empty: