我有一个 OSGi 应用程序,它有一个命令行界面和一个 GWT 界面。我有一个单独的包负责发送电子邮件。它使用 Apache Commons 电子邮件。
电子邮件包仅提供一种发送电子邮件的方法,并且所有属性目前都是硬编码的。
当我从命令行发送电子邮件时,它会获得对捆绑包的引用并毫无问题地发送电子邮件。
当我从 GWT 界面发送电子邮件时,它会获取对捆绑包的引用并尝试发送电子邮件,然后抛出以下异常
org.apache.commons.mail.EmailException: Sending the email to the following server failed : mail.interzet.ru:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
at org.apache.commons.mail.Email.send(Email.java:1267)
at com.ardor.email.internal.EmailServiceImpl.send(EmailServiceImpl.java:134)
at com.ardor.email.internal.EmailServiceImpl.sendChangeEmail(EmailServiceImpl.java:66)
at com.ardor.web.server.CustomerProxyServiceImpl.changeEmail(CustomerProxyServiceImpl.java:93)
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:597)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:558)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:488)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:520)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:973)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:417)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:907)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:442)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:941)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:801)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:224)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:51)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:586)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:44)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
at java.lang.Thread.run(Thread.java:662)
Caused by: javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp
at javax.mail.Session.getProvider(Session.java:229)
at javax.mail.Session.getTransport(Session.java:338)
at javax.mail.Session.getTransport(Session.java:368)
at javax.mail.Transport.send(Transport.java:67)
at javax.mail.Transport.send(Transport.java:48)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
怎么会这样?它正在运行相同的代码
HtmlEmail email = new HtmlEmail();
email.setHostName(SMTP_HOST);
email.setAuthentication(SMTP_USER, SMTP_PASS);
email.setFrom(SMTP_EMAIL, SMTP_NAME);
email.addTo(emailAddress, customerName);
email.setSubject("Subject");
email.setTextMsg("This is my message");
email.setHtmlMsg("This is the HTML");
email.send();
困惑!