Setting up a CONNECT Direct Mail Poller
Version History
Version | Date | Author | Description |
---|---|---|---|
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).
<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)
<!-- 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.
# 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
# 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).