Connect to Microsoft Exchange Server with Spring Integration Mail

随声附和 提交于 2019-12-02 00:42:23

Found it out now. It doesn't has to do something with the connection string. For those who want to connect to Exchange, here some hints.

Here's my config:

<util:properties id="javaMailProperties">
    <prop key="mail.imaps.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
    <prop key="mail.imap.starttls.enable">true</prop>
    <prop key="mail.imaps.socketFactory.fallback">false</prop>
    <prop key="mail.store.protocol">imaps</prop>
    <prop key="mail.debug">true</prop>
</util:properties>

<mail:inbound-channel-adapter id="imapAdapter"
    store-uri="imap://<username>:<password>@<exchange-url>/INBOX" channel="recieveEmailChannel"
    should-delete-messages="false" should-mark-messages-as-read="false"
    auto-startup="true" java-mail-properties="javaMailProperties">
    <int:poller fixed-delay="5"
    time-unit="SECONDS" />
</mail:inbound-channel-adapter>

<int:channel id="recieveEmailChannel" />

<int:service-activator input-channel="recieveEmailChannel"
    ref="reviewMailService" method="receive" />

Typically Exchange uses Imaps with STARTTLS connection.

To perform the SSL handshake, you can use the InstallCert Java program: http://code.google.com/p/java-use-examples/source/browse/trunk/src/com/aw/ad/util/InstallCert.java

  1. The first node after the imaps:// needs to be the fqdn of the server, not the domain (e.g. email.earth.com).
  2. There's a FAQ about exchange credentials here http://www.oracle.com/technetwork/java/faq-135477.html
  3. IIRC, IMAP is not enabled by default on Exchange and the admin has to enable it.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!