SmarterMail REST Wrapper

I recently switched to a web hosting provider after running my own servers for over 10 years. It's been an amazing burden off of my shoulders and has allowed me to focus on what's actually on my sites vs. what is running them.

One of the biggest challenges I faced over the years has been managing an email system that grew to close to 100,000 accounts. With the level of SPAM out there, it has been a real challenge. Now that we moved to a new provider, we no longer have the fine-grained control that we once did, but with the advent of web services it makes much of that irrelevant.

I created this CFC for managing email aliases and users on HostMySite.com's email servers, but this should work at any provider where SmarterMail's web services are made available. It has been tested with version 3 Enterprise but will probably work with others too.

The CFC has the following methods:

  • init(ServiceURL, AuthUserName, AuthPassword, DomainName) - initialize CFC (all parameters required). ServiceURL is URL of the REST Web Service (without the '/Services/...')
  • getAliases() - list all aliases.
  • getAlias(AliasName) - get forwarding addresses for a specific alias.
  • addAlias(AliasName, Addresses) - add a new alias with one or more forwarding addresses.
  • updateAlias(AliasName, Addresses) - updates alias with new forwarding addresses.
  • deleteAlias(AliasName) - removes an alias.
  • getUsers() - list all user accounts.
  • addUser(NewUsername, NewPassword, FirstName, LastName, maxMailboxSize, IsDomainAdmin) - add a new user account. maxMailboxSize is optional and defaults to 25 megabytes. IsDomainAdmin is also optional and defaults to false.
  • deleteUser(Username) - deletes a user account.
  • getDomainAliases() - list all domain aliases.
  • addDomainAlias(NewDomain) - adds a domain alias.
  • deleteDomainAlias(Domain) - deletes a domain alias.

Two test scripts are included - one which handles aliases and another user accounts. You must modify the first 3 lines of each with your account information, then just pull them up in a browser.

This is an initial release. There is nothing else planned at this time, so let me know if you need something. This should run fine on ColdFusion 6, 7, or 8, and probably earlier version too as long as you can parse an XML document.

This is released as open-source. The current version is 1.1 and you can visit the project page and download here.

Related Blog Entries

TweetBacks
Comments
Raymond Camden's Gravatar Hey quick question. I just today discovered the docs for the web services for SmarterMail. Where did you find REST docs?
# Posted By Raymond Camden | 2/5/07 12:47 PM
Joe Danziger's Gravatar Hey Ray.. I think everything I used can be found here:
http://www.smartertools.com/Help/SmarterMail/v3/To...

To find the actual parameters that were necessary, I probably just called up the specified method in a browser and I think it will prompt you for them.
# Posted By Joe Danziger | 2/5/07 2:38 PM
Raymond Camden's Gravatar Ah - I bet the web services were added to v4.
# Posted By Raymond Camden | 2/5/07 2:41 PM
Joe Danziger's Gravatar Actually I think they should be available as of version 3. Check the /v3/ in the URL. I am using them with v3.3.2543 from HostMySite.com.
# Posted By Joe Danziger | 2/5/07 3:09 PM
Dan Lambert's Gravatar Hey guys, thanks for working on this. I have found it extremely useful. I am getting the following error, though, and I'm not quite sure what it means. Any help would be appreciated.

Thanks!
Dan

An error occured while Parsing an XML document.
Content is not allowed in prolog.

The error occurred in C:\Inetpub\wwwroot\Clients\homesearch\loginapp\smartermail.cfc: line 203

201 :       </CFHTTP>
202 :
203 :       <CFSET data = xmlParse(cfhttp.FileContent)>
204 :       
205 :       <CFSET thisResult = structNew()>
# Posted By Dan Lambert | 3/25/07 4:52 PM
Rick Germany's Gravatar Hello-

This has worked great with Smartermail 3, but I get an error when I upgraded to Smartermail 4:

Server Error in '/SmarterMail' Application.
________________________________________
Request format is unrecognized for URL unexpectedly ending in '/GetAlias'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/GetAlias'.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/GetAlias'.]
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +490982
System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +104
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +175
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +120
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

________________________________________
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
-----------------------------------------------------------------------------

Any ideas?

Thanks,
Rick
# Posted By Rick Germany | 6/13/07 12:04 AM
Andy's Gravatar Thanx for the post. It's useful. CF is the best :))

http://garden4u.cn
# Posted By Andy | 7/16/07 1:58 PM
# Posted By rqrr | 7/29/09 3:54 PM