Troubleshooting ErrorHandler example mailing problem - java.net.ConnectException
In Mule1.4.1, the errorhandler example to mail FatalException XML doesn't work by default. Below is the exception when one tries to mail the XML:
********************************************************************************
Message : Unable to connect to mail transport.
Type : org.mule.umo.endpoint.EndpointException
Code : MULE_ERROR-59999
JavaDoc : http:********************************************************************************
Exception stack is:
1. Connection refused: connect (java.net.ConnectException)
java.net.PlainSocketImpl:-2 (http:2. Could not connect to SMTP host: localhost, port: 25 (javax.mail.MessagingException)
com.sun.mail.smtp.SMTPTransport:1282 (http:3. Unable to connect to mail transport. (org.mule.umo.endpoint.EndpointException)
org.mule.providers.email.SmtpMessageDispatcher:60 (http:********************************************************************************
Root Exception stack trace:
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
The getHost method in SmtpConnector (declared in email.properties) is never used for emailing. Whenever an smtp host is required, it is always retrieved from the host possessed by an EndPoint (host in UMOEndpointURI). By default, this value is never set and always refers to localhost.
Solution alternative
We need to declare the smtp host in the mule-config.xml. Below is a snippet of the XML used for mailing:
<endpoint address="smtp://mail.mySMTP.com.au?address=${email.toAddress}" transformers="ErrorMessageToExceptionBean ExceptionBeanToXML StringToEmailMessage">
<properties>
<property name="fromAddress" value="${email.fromAddress}" />
<property name="subject" value="${email.subject}" />
<property name="replyToAddresses" value=""/>
</properties>
</endpoint>