Lucee 5: application defined mailservers

19 October 2017

With Docker all the rage, we're admittedly still some way off the ideal of a completely containerized deployment platform for our applications but it's a direction we definitely wish to go in.

A prerequisite for doing so is that all configuration is defined in code rather than needing to be set up manually.

Even with the old-school "check-list" approach to application/server deployments, any reduction in the number of manual steps involved has an immediately beneficial effect. It's just quicker and less error-prone.

Setting up datasources is one example of a tedious chore that we no longer need worry about since the introduction of per-application datasource definitions in Lucee some time ago.

Lucee 5 has added another aspect of the application environment that can be configured within your application code instead of needing to be pre-defined in the admin. The SMTP mailserver you want to be used when sending mail from the app can now be defined in your Application.cfc is as follows:


this.mailservers =[ {
	 host: "smtp.myserver.com"
	,port: 25
	,username: ""
	,password: ""
	,ssl: false
	,tls: false
	,lifeTimespan: CreateTimeSpan( 0, 0, 1, 0 ) //Overall timeout for the connections established to the mail server.
	,idleTimespan: CreateTimeSpan( 0, 0, 0, 10 ) //Idle timeout for the connections established to the mail server.
} ];

Just as in the admin, you can define fallback servers by adding further structs to the array.

Env vars

It's very likely that the mailserver you use in development differs from production. I use a "dummy" server in dev which generates the mail for viewing without sending it anywhere. In prod we obviously use a fully functional SMTP server.

You could use conditional code to supply different values according to where the app is running, but this is the perfect place for environment variables as discussed in my previous post.


this.mailservers = [ { host: server.system.environment.MAILSERVER_HOST } ];

Posted by Julian on .

Comments

  • Formatting comments: See this list of formatting tags you can use in your comments.
  • Want to paste code? Enclose within <pre><code> tags for syntax higlighting and better formatting and if possible use script. If your code includes "self-closing" tags, such as <cfargument>, you must add an explicit closing tag, otherwise it is likely to be mangled by the Disqus parser.
Back to the top