Configuring SMTP mail in Ctl to support success/error handler notification

100 views
Skip to first unread message

Anthony Shortland

unread,
Oct 8, 2009, 12:03:17 AM10/8/09
to ControlTier Accounting
I started with the notion of writing this up on the Wiki, but it turns out that there are too many loose ends to make a good job of it!

The standard workflow and dispatch command types include support for configuring both success and failure email notification, and both Workbench and ProjectBuilder know how to generate notification code (success-handler and error-handler XML) based on a few configuration elements (e.g. http://wiki.controltier.org/wiki/Type-v10.xml#workflow & http://wiki.controltier.org/wiki/Type-v10.xml#dispatch-command).

Here's the mail task code generated by Workbench for both types of notification for each command type (under 3.4.8):

<mail from="${framework.email.from}" replyto="${framework.email.replyto}" mailhost="${framework.email.mailhost}" mailport="${framework.email.mailport}" user="${framework.email.user}" password="${framework.email.password}" ssl="${framework.email.ssl}" tolist="ant...@dtosolutions.com" subject="[${context.type}:${context.name} @ ${framework.node}] ${command.name} - ERROR" messagefile="${modules.dir}/Deployment/templates/notice.html" messagemimetype="text/html" files="${command.log.file}" failonerror="${framework.email.failonerror}"/>

<mail from="${framework.email.from}" replyto="${framework.email.replyto}" mailhost="${framework.email.mailhost}" mailport="${framework.email.mailport}" user="${framework.email.user}" password="${framework.email.password}" ssl="${framework.email.ssl}" tolist="ant...@dtosolutions.com" subject="[${context.type}:${context.name} @ ${framework.node}] ${command.name} - SUCCESS" messagefile="${modules.dir}/Deployment/templates/notice.html" messagemimetype="text/html" files="${command.log.file}" failonerror=
"${framework.email.failonerror}"/> 

Firstly, this is a straight use of the the Ant mail core task (http://ant.apache.org/manual/CoreTasks/mail.html).

Secondly, you'll note that there is quite a list of properties that this code relies upon:

command.log.file
command.name
context.name
context.type
framework.email.failonerror
framework.email.from
framework.email.mailhost
framework.email.mailport
framework.email.password
framework.email.replyto
framework.email.ssl
framework.email.user
framework.node
modules.di
r

 Here are the property values from the execution of a sample deployment against a default ControlTier 3.4.8 installation:

[anthony@centos52 tmp]$ ctl -p development -t MyDeployment -o myDeployment -c Properties -- -format plain | sh doegrep
command.name=Properties
context.name=myDeployment
context.type=MyDeployment
framework.email.failonerror=true
framework.email.from=root@localdomain
framework.email.mailhost=localhost
framework.email.mailport=25
framework.email.password=
framework.email.replyto=do-not-reply
framework.email.ssl=false
framework.email.user=
framework.node=centos52
modules.dir=/home/anthony/ctier/ctl/depots/development/modules

Now, the other side of the story is that on a modern Linux/Unix system (with some reasonable system administration standards and conventions in place) you can reasonably expect SMTP mail to be working:

[anthony@centos52 tmp]$ telnet localhost 25
Trying 127.0.0.1...
Connected to user1.centos52 (127.0.0.1).
Escape character is '^]'.
220 localhost.localdomain ESMTP Sendmail 8.13.8/8.13.8; Wed, 7 Oct 2009 20:53:13 -0700
^]
telnet> Connection closed.
 
... works for me on my CentOS 5.2 image running under VMware on my Mac (amazingly!).

So much for background information, here's where the fun starts: tying the two together!

Running the notification enabled workflow generates the following error:

[anthony@centos52 etc]$ ctl -p development -t MyDeployment -o myDeployment -c MyWorkflowCommand
Start: "" commands: MyAntCommand
begin workflow command (1/1) -> "MyAntCommand " ...
end workflow command (1/1) -> "MyAntCommand "
[command.timer.development.MyDeployment.MyWorkflowCommand: 0.502 sec]
Workflow completed. execution time: 0.502 sec
Sending email: [MyDeployment:myDeployment @ centos52] MyWorkflowCommand - SUCCESS
Failed to send email: Exception reading response

Command failed: Problem while sending mime mail:

Which, when run in verbose mode, yields the following stack trace:

        at java.lang.reflect.Method.invoke(Method.java:585)
        at launcher.CtlLauncher.main(CtlLauncher.java:34)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
        at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:523)
        at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355)

Looking back at the framework mail properties shows "framework.email.ssl=true" be default. This property is supplied to the ssl attribute of the Ant mail command which "indicates whether you need TLS/SSL". I set it to "false".
Switching the property value to false, yields the next problem:

javax.mail.AuthenticationFailedException
        at javax.mail.Service.connect(Service.java:306)
        at javax.mail.Service.connect(Service.java:156)
        at javax.mail.Service.connect(Service.java:105)

This one was a little more subtle, but I tracked it down to "framework.email.mailhost=mail" which I switched to "localhost" to yield:

com.sun.mail.smtp.SMTPSendFailedException: 553 5.5.4 <root>... Domain name required for sender address root

        at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
        at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)

This one was due to "framework.email.from=root" which I changed to "root@localdomain":

[anthony@centos52 etc]$ ctl -p development -t MyDeployment -o myDeployment -c MyWorkflowCommand
Start: "" commands: MyAntCommand
begin workflow command (1/1) -> "MyAntCommand " ...
end workflow command (1/1) -> "MyAntCommand "
[command.timer.development.MyDeployment.MyWorkflowCommand: 0.390 sec]
Workflow completed. execution time: 0.390 sec
Sending email: [MyDeployment:myDeployment @ centos52] MyWorkflowCommand - SUCCESS
Sent email with 1 attachment

... success!

Now you may be wondering where I changed all these properties:

[anthony@centos52 etc]$ cd $CTL_BASE/etc
[anthony@centos52 etc]$ pwd
/home/anthony/ctier/ctl/etc
[anthony@centos52 etc]$ diff framework.properties framework.properties.orig 
72c72
< framework.email.from = root@localdomain
---
> framework.email.from = root
76c76
< framework.email.mailhost = localhost
---
> framework.email.mailhost = mail
81c81
< framework.email.ssl = false
---
> framework.email.ssl = true

... note also that rather the manually editing framework.properties, you can set this all up when you install ControlTier:

[anthony@centos52 ControlTier-3.4.8]$ fgrep framework.email default.properties 
framework.email.replyto=do-not-reply
framework.email.user=
framework.email.mailhost=mail
framework.email.ssl=true
framework.email.password=
framework.email.tolist=root
framework.email.failonerror=true
framework.email.mailport=25
framework.email.from=root

... by overriding the default properties.

Thanks,

Anthony.

Reply all
Reply to author
Forward
0 new messages