I could not get mail integration working, seems to be connected to the gmail mail server but not getting any mail notifications when new mail arrieved, can anyone help me with the setup? Here is my application context file. verified IMAP enabled on the gmail account also.
ApplicationContext.xml
application.propertiesCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:int="http://www.springframework.org/schema/integration" xmlns:mail="http://www.springframework.org/schema/integration/mail" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail-2.0.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" default-lazy-init="false" default-autowire="no"> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name='locations'> <value>apiclient/application.properties</value> </property> </bean> <util:properties id="javaMailProperties"> <prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop> <prop key="mail.imap.socketFactory.fallback">false</prop> <prop key="mail.store.protocol">imaps</prop> <prop key="mail.debug">true</prop> <prop key="mail.imaps.timeout">5</prop> </util:properties> <mail:imap-idle-channel-adapter id="customAdapter" store-uri="${imap.uri}" channel="recieveChannel" auto-startup="true" should-delete-messages="${imap.shouldDeleteMessage}" should-mark-messages-as-read="${imap.shouldMarkMessageAsRead}" java-mail-properties="javaMailProperties"/> <int:service-activator id="messageActivator" input-channel="recieveChannel" ref="emailReceiverService" method="receive"/> <int:channel id="recieveChannel"> <int:interceptors> <int:wire-tap channel="logger"/> </int:interceptors> </int:channel> <int:logging-channel-adapter id="logger" level="DEBUG"/> <bean id="emailReceiverService" class="com.otcgh.eoxlive.apiclient.email.EmailService"> </bean> </beans>
EmailService.javaCode:imap.uri=imaps://myusername:mypassword@imap.gmail.com:993/INBOX imap.debug=true imap.poolerSecondsDelay=5 imap.shouldDeleteMessage=false imap.shouldMarkMessageAsRead=false
ApplicationLauncher.javaCode:import java.io.IOException; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; import org.apache.log4j.Logger; public class EmailService { private final static Logger logger = Logger.getLogger(EmailService.class); public void receive(MimeMessage message) { try { logger.info("Message: " + (String)message.getContent()); } catch (IOException e) { e.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } } }
Code:import java.util.concurrent.CountDownLatch; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class ApplicationLauncher { private static final String CONTEXT_ROOT = "apiclient"; private static final String APPLICATION_CONTEXT = CONTEXT_ROOT + "/ApplicationContext.xml"; private static final CountDownLatch shutdownLatch = new CountDownLatch(1); public void stop() { shutdownLatch.countDown(); } public static void main(String[] args) { try { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT); ctx.registerShutdownHook(); shutdownLatch.await(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }
Output from the program run:
DEBUG: JavaMail version 1.4.1ea-SNAPSHOT
DEBUG: successfully loaded file: C:\Java\jdk1.6.0_23\jre\lib\javamail.providers
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Pro vider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport ,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provide r[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport ,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: successfully loaded file: C:\Java\jdk1.6.0_23\jre\lib\javamail.address.map
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384


Reply With Quote