getting error in sending the mail in spring integration..!!
HI ,
I am developing an application in which thwe moment the message come to a channel that message should be emailed to anyone on gmail id ...but I am getting the below exception....
Quote:
Exception in thread "main" org.springframework.integration.MessageHandlingExc eption: error occurred in message handler [org.springframework.integration.mail.MailSendingMe ssageHandler#0]
at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:84)
at org.springframework.integration.dispatcher.Unicast ingDispatcher.doDispatch(UnicastingDispatcher.java :110)
at org.springframework.integration.dispatcher.Unicast ingDispatcher.dispatch(UnicastingDispatcher.java:9 7)
at org.springframework.integration.channel.AbstractSu bscribableChannel.doSend(AbstractSubscribableChann el.java:61)
at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:157)
at org.springframework.integration.channel.AbstractMe ssageChannel.send(AbstractMessageChannel.java:128)
at org.springframework.integration.core.MessagingTemp late.doSend(MessagingTemplate.java:288)
at org.springframework.integration.core.MessagingTemp late.send(MessagingTemplate.java:149)
at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.sendMessage(AbstractRep lyProducingMessageHandler.java:176)
at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.sendReplyMessage(Abstra ctReplyProducingMessageHandler.java:160)
at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.produceReply(AbstractRe plyProducingMessageHandler.java:125)
at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleResult(AbstractRe plyProducingMessageHandler.java:119)
at org.springframework.integration.handler.AbstractRe plyProducingMessageHandler.handleMessageInternal(A bstractReplyProducingMessageHandler.java:101)
at
java.net.SocketException: Operation timed out: connect:could be due to invalid address. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
nested exception is:
java.net.SocketException: Operation timed out: connect:could be due to invalid address; message exceptions (1) are:
Failed message 1: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
nested exception is:
java.net.SocketException: Operation timed out: connect:could be due to invalid address
at org.springframework.mail.javamail.JavaMailSenderIm pl.doSend(JavaMailSenderImpl.java:400)
at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:306)
at org.springframework.mail.javamail.JavaMailSenderIm pl.send(JavaMailSenderImpl.java:296)
at org.springframework.integration.mail.MailSendingMe ssageHandler.handleMessageInternal(MailSendingMess ageHandler.java:73)
at org.springframework.integration.handler.AbstractMe ssageHandler.handleMessage(AbstractMessageHandler. java:78)
... 19 more
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
nested exception is:
java.net.SocketException: Operation timed out: connect:could be due to invalid address
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTra nsport.java:1282)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SM TPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at org.springframework.mail.javamail.JavaMailSenderIm pl.doSend(JavaMailSenderImpl.java:389)
... 23 more
Caused by: java.net.SocketException: Operation timed out: connect:could be due to invalid address
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl .java:391)
at java.net.PlainSocketImpl.connectToAddress(PlainSoc ketImpl.java:252)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava:239)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.j ava:385)
at java.net.Socket.connect(Socket.java:543)
at java.net.Socket.connect(Socket.java:493)
at com.sun.mail.util.SocketFetcher.createSocket(Socke tFetcher.java:232)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFe tcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTra nsport.java:1250)
From this error One thing is sure is that there is some problem with the configuration section...below is the configuration section....
Code:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import java.util.Properties;
@Configuration
public class MailConfiguration {
@Bean
public JavaMailSenderImpl mailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.gmail.com");
mailSender.setPort(587);
mailSender.setUsername("somemailid@gmail.com");
mailSender.setPassword("somepasswd");
Properties properties = new Properties();
properties.setProperty("mail.smtp.starttls.enable", "true");
properties.setProperty("mail.smtp.auth", "true");
mailSender.setJavaMailProperties(properties);
return mailSender;
}
}
and below is the xml configuration that I am using....
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:int="http://www.springframework.org/schema/integration"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:file="http://www.springframework.org/schema/integration/file"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jms="http://www.springframework.org/schema/integration/jms"
xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mail="http://www.springframework.org/schema/integration/mail"
xmlns:stream="http://www.springframework.org/schema/integration/stream"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/integration/file
http://www.springframework.org/schema/integration/file/spring-integration-file-2.0.xsd
http://www.springframework.org/schema/integration/jms
http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream-1.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.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/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail-2.0.xsd">
<context:component-scan base-package="com.walgreens.ods.producer" />
<context:component-scan base-package="com.walgreens.ods.exceptions" />
<!-- <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL">
<value>tcp://localhost:61616</value>
</property>
</bean>-->
<!--<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
</bean>
<int:poller id="poller" default="true">
<int:interval-trigger interval="200" />
</int:poller>
<int:channel id="receive-jms-message-channel">
<int:queue capacity="10" />
</int:channel>
<int:channel id="input"></int:channel>
<jms:outbound-channel-adapter channel="input" destination-name="errorQueue"></jms:outbound-channel-adapter>
<jms:message-driven-channel-adapter
id="mq-message-listner" channel="receive-jms-message-channel"
destination-name="errorQueue" concurrent-consumers="10" />-->
<int:channel id="receive-jms-message-channel">
</int:channel>
<mail:outbound-channel-adapter channel="outboundMail"
mail-sender="mailSender"/>
<mail:header-enricher input-channel="receive-jms-message-channel" output-channel="outboundMail">
<mail:to value="any@gmail.com"/>
<mail:from value="somemailid@gmail.com"/>
<mail:subject value="Test"/>
</mail:header-enricher>
<int:channel id="outboundMail"></int:channel>
</beans>
Please gudide me what is wrong with my configuration settings regarding gmail and how to overcome from this error..!!!:mad::mad: