Announcement Announcement Module
Collapse
No announcement yet.
why not work spring mail??? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • why not work spring mail???

    hello, can you help me?


    FeedbackService.java
    Code:
    package com.lingoosoft.service.impl;
    
    import java.util.Date;
    
    import org.springframework.mail.MailSender;
    import org.springframework.mail.SimpleMailMessage;
    
    import com.lingoosoft.model.Feedback;
    import com.lingoosoft.service.IFeedbackService;
    import com.lingoosoft.service.BaseService;
    
    public class FeedbackService extends BaseService implements IFeedbackService {
    
    	private MailSender mailSender;
    
    	public FeedbackService() {
    	}
    
    	public void setMailSender(MailSender mailSender) {
    		this.mailSender = mailSender;
    	}
    
    	public void send(Feedback feedback) {
    		SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    		simpleMailMessage.setSubject(feedback.getSubject());
    		simpleMailMessage.setFrom(feedback.getFrom());
    		simpleMailMessage.setTo(feedback.getTo());
    		simpleMailMessage.setText(feedback.getText());
    		simpleMailMessage.setSentDate(new Date());
    
    		mailSender.send(simpleMailMessage);
    	}
    
    }
    application-Context.xml
    Code:
    	<bean id="feedbackService"
    		class="com.lingoosoft.service.impl.FeedbackService">
    		<property name="mailSender">
    			<ref bean="mailSender" />
    		</property>
    	</bean>
    	<bean id="mailSender"
    		class="org.springframework.mail.javamail.JavaMailSenderImpl">
    		<property name="host" value="${mail.smtp.host}" />
    		<property name="port" value="${mail.smtp.port}" />
    		<property name="protocol" value="${mail.transport.protocol}" />
    		<property name="username" value="${mail.smtp.username}" />
    		<property name="password" value="${mail.smtp.password}" />
    		<property name="javaMailProperties">
    			<props> 
    				<prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
    				<prop key="mail.smtp.socketFactory.port">${mail.smtp.socketFactory.port}</prop>
    				<prop key="mail.smtp.socketFactory.class">${mail.smtp.socketFactory.class}</prop>
    				<prop key="mail.smtp.socketFactory.fallback">${mail.smtp.socketFactory.fallback}</prop>
    				<prop key="mail.smtp.timeout">${mail.smtp.timeout}</prop>
    			</props> 
    		</property>
    	</bean>
    mail.properties
    Code:
    ## Properties file with mail settings. ##
    
    # common #
    mail.smtp.host                   = smtp.gmail.com
    mail.smtp.port                   = 465
    mail.transport.protocol          = smtp
    mail.smtp.username               = [email protected]
    mail.smtp.password               = 123
    
    # <property name="javaMailProperties"> #
    mail.smtp.auth                   = true
    mail.smtp.socketFactory.port     = 465
    mail.smtp.socketFactory.class    = javax.net.ssl.SSLSocketFactory
    mail.smtp.socketFactory.fallback = false
    mail.smtp.timeout                = 25000
    mail.smtp.starttls.enable        = true
    Last edited by lingoosoft; Apr 9th, 2007, 11:37 PM.

  • #2
    Exception
    Code:
    ERROR: Servlet.service() for servlet Faces Servlet threw exception
          2007-04-10 12:20:56,984 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/vote0_2].[Faces Servlet] 71240 http-8080-Processor24
    org.springframework.mail.MailSendException; nested exception details (1) are:
    Failed message 1:
    javax.mail.MessagingException: IOException while sending message;
      nested exception is:
    	java.io.IOException: No content
    	at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:566)
    	at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:388)
    	at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:298)
    	at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:284)
    	at com.lingoosoft.service.impl.FeedbackService.send(FeedbackService.java:32)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:585)
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:299)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
    	at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
    	at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:54)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
    	at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:54)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    	at $Proxy11.send(Unknown Source)
    	at com.lingoosoft.present.impl.FeedbackHandler.send(FeedbackHandler.java:53)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:585)
    	at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
    	at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
    	at javax.faces.component.UICommand.broadcast(UICommand.java:109)
    	at org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:180)
    	at org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:158)
    	at org.ajax4jsf.framework.ajax.AjaxViewRoot.processApplication(AjaxViewRoot.java:329)
    	at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
    	at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
    	at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
    	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    	at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:96)
    	at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:220)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    	at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:264)
    	at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
    	at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
    	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
    	at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
    	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
    	at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
    	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
    	at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142)
    	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
    	at org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:81)
    	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
    	at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:217)
    	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
    	at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:106)
    	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
    	at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:229)
    	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
    	at org.acegisecurity.concurrent.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:95)
    	at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
    	at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:148)
    	at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
    	at java.lang.Thread.run(Thread.java:595)

    Comment


    • #3
      Check this post about sending secure smtp: http://forum.springframework.org/showthread.php?t=33667

      Comment


      • #4
        thx! I read the article, and follow the guide, I use spring 2.0.3

        but cause the same exception:
        Code:
        ERROR: Servlet.service() for servlet Faces Servlet threw exception
              2007-04-10 15:27:39,419 org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/vote0_2].[Faces Servlet] 60686 http-8080-Processor25
        org.springframework.mail.MailSendException; nested exception details (1) are:
        Failed message 1:
        javax.mail.MessagingException: IOException while sending message;
          nested exception is:
        	java.io.IOException: No content
        Code:
        package com.lingoosoft.service.impl;
        
        import java.util.Date;
        
        import org.springframework.mail.MailSender;
        import org.springframework.mail.SimpleMailMessage;
        
        import com.lingoosoft.model.Feedback;
        import com.lingoosoft.service.IFeedbackService;
        import com.lingoosoft.service.BaseService;
        
        public class FeedbackService extends BaseService implements IFeedbackService {
        
        	private MailSender mailSender;
        	
        	private SimpleMailMessage simpleMailMessage;
        
        	public FeedbackService() {
        	}
        
        	public void setMailSender(MailSender mailSender) {
        		this.mailSender = mailSender;
        	}
        	
        	public void setSimpleMailMessage(SimpleMailMessage simpleMailMessage) {
        		this.simpleMailMessage = simpleMailMessage;
        	}
        
        	public void send(Feedback feedback) {
        		SimpleMailMessage simpleMailMessage = new SimpleMailMessage(this.simpleMailMessage);
        		simpleMailMessage.setSubject(feedback.getSubject());
        		simpleMailMessage.setFrom(feedback.getFrom());
        		simpleMailMessage.setText(feedback.getText());
        		simpleMailMessage.setSentDate(new Date());
        
        		mailSender.send(simpleMailMessage);
        	}
        
        }
        Code:
        	<!-- 反馈信息服务 -->
        	<bean id="feedbackService"
        		class="com.lingoosoft.service.impl.FeedbackService">
        		<property name="mailSender">
        			<ref local="mailSender" />
        		</property>
        		<property name="simpleMailMessage">
        			<ref local="simpleMailMessage" />
        		</property>
        	</bean>
        
        
        
        	<!-- 邮件服务器登录认证信息 -->
        	<bean id="smtpAuthenticator"
        		class="com.lingoosoft.mail.SmtpAuthenticator">
        		<property name="username" value="${mail.smtp.username}" />
        		<property name="password" value="${mail.smtp.password}" />
        	</bean>
        
        	<!-- 认证会话 -->
        	<bean id="mailSession" class="javax.mail.Session"
        		factory-method="getInstance">
        		<constructor-arg>
        			<props>
        				<prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
        				<prop key="mail.smtp.socketFactory.port">
        					${mail.smtp.socketFactory.port}
        				</prop>
        				<prop key="mail.smtp.socketFactory.class">
        					${mail.smtp.socketFactory.class}
        				</prop>
        				<prop key="mail.smtp.socketFactory.fallback">
        					${mail.smtp.socketFactory.fallback}
        				</prop>
        				<prop key="mail.smtp.timeout">
        					${mail.smtp.timeout}
        				</prop>
        			</props>
        		</constructor-arg>
        		<constructor-arg ref="smtpAuthenticator" />
        	</bean>
        
        	<!-- 邮件发送器 -->
        	<bean id="mailSender"
        		class="org.springframework.mail.javamail.JavaMailSenderImpl">
        		<property name="host" value="${mail.smtp.host}" />
        		<property name="port" value="${mail.smtp.port}" />
        		<property name="protocol" value="${mail.transport.protocol}" />
        		<property name="session" ref="mailSession" />
        	</bean>
        	
        	<!-- 简单邮件内容 -->
        	<bean id="simpleMailMessage"
        		class="org.springframework.mail.SimpleMailMessage">
        		<property name="to" value="${mail.sendTo}" />
        	</bean>
        Code:
        ## Properties file with mail settings. ##
        
        # Common SMTP #
        mail.smtp.host                   = smtp.gmail.com
        mail.smtp.port                   = 465
        mail.transport.protocol          = smtp
        mail.smtp.username               = [email protected]
        mail.smtp.password               = 123
        
        # SSL SMTP #
        mail.smtp.auth                   = true
        mail.smtp.socketFactory.port     = 465
        mail.smtp.socketFactory.class    = javax.net.ssl.SSLSocketFactory
        mail.smtp.socketFactory.fallback = false
        mail.smtp.timeout                = 25000
        mail.smtp.starttls.enable        = true
        
        # Mail #
        mail.sendTo                      = [email protected]

        Comment


        • #5
          any one can help!!!!!!

          help!!!!

          Comment


          • #6
            .setText(text);

            the text equals "null" cause the Exception: No Context

            Comment

            Working...
            X