Announcement Announcement Module
Collapse
No announcement yet.
Problem with mail integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with mail integration

    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
    Code:
    <?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>
    application.properties
    Code:
    imap.uri=imaps://myusername:[email protected]:993/INBOX
    imap.debug=true
    imap.poolerSecondsDelay=5
    imap.shouldDeleteMessage=false
    imap.shouldMarkMessageAsRead=false
    EmailService.java
    Code:
    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();
    		}
    	}
    	
    }
    ApplicationLauncher.java
    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

  • #2
    Have you looked at the samples? http://git.springsource.org/+spring-...ration/samples

    http://git.springsource.org/spring-i...ter/basic/mail

    It actually uses GMAIL configuration

    Comment


    • #3
      Thank You Mr. Oleg Zhurakousky

      I followed the example setup as in the location you provided, this code is very same, Its not working I turned the debug also on, no error no further information in the log as you see in the output. Can you give me clues on whats missing. I was not able to get the example working exactly same out put even with the sample code.

      Comment


      • #4
        I think figured out:

        while browsing through this forum found references that state the uri must start with imap not imaps. Changed the imap.uri in the properties file as follows and the program working now its able to get the emails.

        Code:
        imap.uri=imap://myusername:[email protected]:993/inbox
        imap.debug=true
        imap.poolerSecondsDelay=5
        imap.shouldDeleteMessage=false
        imap.shouldMarkMessageAsRead=false
        Now I have to see how to extract the attachments from the email. If anyone know can you please post some snippets. -Thank You

        Comment


        • #5
          Its not exactly the same.
          You should just be able to use the sample with your credentials.
          Also, you seem to be mixing schemas in the AC configuration. You are using spring 3.0 and 2.5 which leads me to believe that you may also have 2 versions of Spring in the classpath as well as other things.

          Also, since you are using IDLE do you realize that it is an event driven protocol which means that just because you have messages in the mailbox it will not be retrieved until a new message event will occur. This means once you start IDLE adapter you have to then send yourself an email, otherwise use a polling adapter.

          Comment

          Working...
          X