2013-12-15 111 views
4

您好,我是一名嘗試在我的Tomcat服務器上運行郵件通知服務的初學者。當我在本地運行此代碼時,它可以工作,但不會在我將其部署到遠程服務器上時運行 我得到「javax.mail.MessagingException:無法確定本地電子郵件地址」。 我在我的服務器上有一個SSL證書,它可以是這個原因嗎?在Tomcat服務器上運行時,JavaMail停止工作

請你好,如果你覺得我已經忘記了一些東西,那就寫下來,我會更新帖子。 謝謝,這裏是我的代碼。

的applicationContext.xml

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> 
    <property name="host" value="smtp.gmail.com" /> 
    <property name="port" value="25" /> 
    <property name="username" value="[email protected]" /> 
    <property name="password" value="mypassword" /> 
    <property name="javaMailProperties"> 
     <props> 
      <prop key="mail.transport.protocol">smtp</prop> 
      <prop key="mail.smtp.auth">true</prop> 
      <prop key="mail.smtp.starttls.enable">true</prop> 
      <prop key="mail.debug">true</prop> 
     </props> 
    </property> 
</bean> 

MailService.java

@Autowired 
private MailSender mailSender; 

public void sendEventMailToUser(Event event) { 
    SimpleMailMessage message = new SimpleMailMessage(); 
    message.setTo(event.getUser().getEmail().trim()); 
    message.setSubject("appName"); 
    message.setText("Mymessage"); 
    mailSender.send(message); 

} 

從我的郵件調試

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc] 
DEBUG SMTP: useEhlo true, useAuth true 
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false 
220 mx.google.com ESMTP ld10sm15750527lab.8 - gsmtp 
DEBUG SMTP: connected to host "smtp.gmail.com", port: 25 

EHLO 
250-mx.google.com at your service, [91.189.44.73] 
250-SIZE 35882577 
250-8BITMIME 
250-STARTTLS 
250-ENHANCEDSTATUSCODES 
250 CHUNKING 
DEBUG SMTP: Found extension "SIZE", arg "35882577" 
DEBUG SMTP: Found extension "8BITMIME", arg "" 
DEBUG SMTP: Found extension "STARTTLS", arg "" 
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg "" 
DEBUG SMTP: Found extension "CHUNKING", arg "" 
STARTTLS 
220 2.0.0 Ready to start TLS 
EHLO 
250-mx.google.com at your service, [91.189.44.73] 
250-SIZE 35882577 
250-8BITMIME 
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN 
250-ENHANCEDSTATUSCODES 
250 CHUNKING 
DEBUG SMTP: Found extension "SIZE", arg "35882577" 
DEBUG SMTP: Found extension "8BITMIME", arg "" 
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN" 
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg "" 
DEBUG SMTP: Found extension "CHUNKING", arg "" 
DEBUG SMTP: Attempt to authenticate 
AUTH LOGIN 
334 VXNlcm5hbWU6 
c2FtYnVoYXV0b21haWxAZ21haWwuY29t 
334 UGFzc3dvcmQ6 
UGFzc1dvcmQ0Tm93 
235 2.7.0 Accepted 
DEBUG SMTP: use8bit false 
javax.mail.MessagingException: can't determine local email address 
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:906) 
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583) 
    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:416) 
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:306) 
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296) 
    at se.whiffdev.sambuh.utilities.MailService.sendEventMailToUser(MailService.java:68) 
    at se.whiffdev.sambuh.service.impl.EventServiceImpl.updateEvent(EventServiceImpl.java:44) 
    at se.whiffdev.sambuh.mvc.adminuser.AdminUserCalendarController.adminUserCreateUpdateCalendar(AdminUserCalendarController.java:80) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) 
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) 
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) 
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920) 
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:827) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:611) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:744) 
QUIT 
221 2.0.0 closing connection ld10sm15750527lab.8 - gsmtp 
+0

那麼,本地電子郵件地址是什麼?你在開發機器上成功運行這段代碼是什麼? (順便說一下,很好地提出問題) – Ingo

回答