OSGi GWT org.apache.commons.mail.EmailException [英] OSGi GWT org.apache.commons.mail.EmailException

查看:211
本文介绍了OSGi GWT org.apache.commons.mail.EmailException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个OSGi应用程序,它具有一个命令行界面和一个GWT接口。我有一个单独的包,负责发送电子邮件。它使用Apache Commons Email。



电子邮件包只提供一种发送电子邮件的方法,并且所有属性都是硬编码的。



当我从命令行发送电子邮件时,它会获得对该软件包的引用,并发送电子邮件没有任何问题。



当我从GWT界面发送电子邮件,它可以引用该包,并尝试发送电子邮件,然后抛出以下异常。




org.apache.commons.mail.EmailException:将电子邮件发送到以下服务器失败:mail.interzet.ru:25
在org.apache.commons.mail.Email.sendMimeMessage(Email.java: 1242)
在org.apache.commons.mail.Email.send(Email.java:1267)
在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.changeEma il(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)
在java.lang.reflect.Method.invoke(Method.java:597)
在com.google.gwt.user.server.rpc。 RPC.invokeAndEncodeResponse(RPC.java:569)
在com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
在com.google.gwt.user。 server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
在com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
在javax.servlet。 http.HttpServlet.service(HttpServlet.java:755)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
在org.eclipse.jetty.servlet.ServletHolder.handle( ServletHolder.java:55 8)
在org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:488)
在org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
在org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:520)
在org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
在org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:973)
在org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:417)
在org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
在org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:907)
在org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
在org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
在org.eclipse.jetty.server.Server.handle(Server.java:346)
在org.eclips e.jetty.server.HttpConnection.handleRequest(HttpConnection.java:442)
在org.eclipse.jetty.server.HttpConnection $ RequestHandler.content(HttpConnection.java:941)
在org.eclipse。 jetty.http.HttpParser.parseNext(HttpParser.java:801)
在org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:224)
在org.eclipse.jetty.server。 AsyncHttpConnection.handle(AsyncHttpConnection.java:51)
在org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:586)
在org.eclipse.jetty.io.nio。 SelectChannelEndPoint $ 1.run(SelectChannelEndPoint.java:44)
在org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
在org.eclipse.jetty.util.thread .QueuedThreadPool $ 3.run(QueuedThreadPool.java:533)
在java.lang.Thread.run(Thread.java:662)
导致:javax.mail.NoSuchProviderException:无法找到协议提供者:smtp
在javax.mail.Session.getProvider(Session.ja VA:229)在javax.mail.Session.getTransport(Session.java:338
)在javax.mail.Session.getTransport(Session.java:368

在javax.mail .Transport.send(Transport.java:67)
在javax.mail.Transport.send(Transport.java:48)
在org.apache.commons.mail.Email.sendMimeMessage(Email.java :1232)



这怎么可能?它正在运行相同的代码




HTML电子邮件电子邮件=新HTML电子邮件();



  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(这是我的消息);
email.setHtmlMsg(This is the HTML);

email.send();



困惑!

解决方案

我不完全确定为什么,但原来是一个简单的类路径错误。看来OSGi包曾获得javax.mail_1.4.0.jar和战争不能访问它。



我把它添加到应用程序的WEB-INF / lib,它现在可以正常工作。



对于没有从GWT调用的OSGi软件包可以访问它,仍然无法访问它


I have an OSGi application which has a command line interface and a GWT interface. I have a separate bundle that is responsible for sending emails. It uses Apache Commons Email.

The email bundle only provides one method for sending email and all of the properties are hard coded at the moment.

When I send the email from the command line, it gets a reference to the bundle and sends off the email with no problem.

When I send the email from the GWT interface, it gets a reference to the bundle and attempts to send the email and then throws the following exception

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)

How can this be? It is running the same code

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();

Puzzled!

解决方案

I am not completly sure as to why but It turned out to be a simple class path error. It seems the OSGi bundle had access to javax.mail_1.4.0.jar and the war doesn't have access to it.

I added it to the applications WEB-INF/lib and it now works fine.

It still makes no sense to me why it would need access to it as the OSGi bundle can access it when not being called from GWT

这篇关于OSGi GWT org.apache.commons.mail.EmailException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆