Setting up a CONNECT Direct Mail Poller

Version History

VersionDateAuthorDescription
0.1 09/09/2016 Daniel Fernandez Initial Draft


Configure Direct Pollers

Connect's Spring integration provides support for inbound and outbound email message polling.  Email listeners in applications use a dedicated cron task to poll, or check, the mail server for incoming messages.  The cron tasks are Java components that can be used to run automatically at scheduled intervals.  The scheduling of the Direct pollers is configured in <nhinc.properties.dir>/direct.appcontext.xml.  To change the polling intervals, the values in the cron attribute are updated (in seconds).


direct.appcontext.xml - Disabled pollers
    <import resource="direct.beans.xml"/>

    <!-- Set up polling for inbound and outbound direct messages -->
    <!-- This is commented out in the source intentionally. Please see the DirectCore project README.md for more details. -->
    <!--task:scheduled-tasks scheduler="directScheduler">
        <task:scheduled ref="outboundMessagePoller" method="poll" cron="0,30 * * * * *"/>
        <task:scheduled ref="inboundMessagePoller" method="poll" cron="15,45 * * * * *"/>
    </task:scheduled-tasks>
    <task:scheduler id="directScheduler" />
    <bean id="manageTaskScheduler" class="gov.hhs.fha.nhinc.mail.ManageTaskScheduler" init-method="init" destroy-method="clean">
        <constructor-arg ref="directScheduler"/>
    </bean-->

To enable the pollers, uncomment the code snippet from <!--task:scheduled-tasks to </bean--> (see below)

direct.appcontext.xml - Enabled pollers
    <!-- Set up polling for inbound and outbound direct messages -->
    <!-- This is commented out in the source intentionally. Please see the DirectCore project README.md for more details. -->
    <task:scheduled-tasks scheduler="directScheduler">
        <task:scheduled ref="outboundMessagePoller" method="poll" cron="0,30 * * * * *"/>
        <task:scheduled ref="inboundMessagePoller" method="poll" cron="15,45 * * * * *"/>
    </task:scheduled-tasks>
    <task:scheduler id="directScheduler" />
    <bean id="manageTaskScheduler" class="gov.hhs.fha.nhinc.mail.ManageTaskScheduler" init-method="init" destroy-method="clean">
        <constructor-arg ref="directScheduler"/>
    </bean>

Note: Spring uses the cron format, which supports the seconds setting.  In the example above, the pollers are tasked to run every 15 seconds: the outbound message poller against the internal server runs at 0:00 and 0:30 seconds of each minute, and the inbound message poller against the external server runs at 0:15 and 0:45 of each minute.

Configure Mail Server Properties

The <nhinc.properties.dir> contains two property files holding the mail server's settings.  These are direct.mail.external.properties(defines properties for the external mail server) and direct.mail.internal.properties(defines properties for the internal mail server).  Both files contain properties which are used to connect to each mail server.  The properties stored in them are used to connect to each mail server.  Below are contents of the two files.  All properties with names beginning with "connect." are used by the CONNECT Gateway Direct HISP.  The rest of the properties are used by Javamail.  They are used in DirectCore's Spring configuration (direct.beans.xml) for sending and receiving messages.

direct.mail.external.properties
# credentials
connect.mail.user=<external_server_user>
connect.mail.pass=<external_server_password>

# number of direct messages to handle in a batch, can be used to throttle, even out load, and prevent DOS.
connect.max.msgs.in.batch=3

# turn on/off java mail session debugging (true/false), set to false in production.
connect.mail.session.debug=true

# should unhandled messages be deleted from server?
connect.delete.unhandled.msgs=false

# smtp
mail.smtp.host=<external_server_ip>
mail.smtp.auth=true
mail.smtp.port=xxx
mail.smtp.starttls.enable=true

# imap
mail.imaps.host=<external_server_ip>
mail.imaps.port=xxx
direct.mail.internal.properties
# credentials
connect.mail.user=<internal_server_user>
connect.mail.pass=<internal_server_password>

# number of direct messages to handle in a batch, can be used to throttle, even out load, and prevent DOS.
connect.max.msgs.in.batch=3

# turn on/off java mail session debugging (true/false), set to false in production.
connect.mail.session.debug=true

# should unhandled messages be deleted from server?
connect.delete.unhandled.msgs=false

# smtp
mail.smtp.host=<internal_server_ip_address>
mail.smtp.auth=true
mail.smtp.port=xxx
mail.smtp.starttls.enable=true

# imap
mail.imaps.host=<internal_server_ip>
mail.imaps.port=xxx

Import Mail Server Certificate to Keystore

Run this keytool command to import the mail server certificate to the cacerts.jks.  Be sure to run it in the <nhinc.properties.dir> where cacerts.jks is located.  In this example the mail server certificate is called directMail.cer.

keytool -import -v -noprompt -trustcacerts -alias alias -file directMail.cer -keystore cacerts.jks -storepass changeit

Starting the poller

When the Direct taskScheduler is uncommented in direct.appcontext.xml, the poller automatically runs when the server is started. To turn off the poller, the server must be shut down (only commenting out the taskScheduler will not stop the poller from running).