简体   繁体   English

无法在Glassfish上部署的应用程序中发送电子邮件

[英]impossible to send email in application deployed on Glassfish

I've spent literally two days with this, googled it everywhere and still couldnt solve it, let's see if someone finds what I'm doing wrong: 我花了整整两天的时间,用Google搜索它,但仍然无法解决它,让我们看看是否有人发现我在做错什么:

I've defined a javaMail Session in Glassfish, with all the parameters needed to communicate with a mail server (host, user, pass, port, etc..). 我在Glassfish中定义了一个javaMail会话,其中包含了与邮件服务器进行通信所需的所有参数(主机,用户,密码,端口等)。 I deploy an application that looks up that Session using jndi and tries to send an email. 我部署了一个使用jndi查找该Session并尝试发送电子邮件的应用程序。 The code is: 代码是:

InitialContext ctx = new InitialContext();
Session session = (Session) ctx.lookup("mail/javaMailSession");

Message msg = new MimeMessage(session);  
msg.setSubject("test");  
msg.setRecipient(RecipientType.TO, new InternetAddress("zzz@yyy.com", "zzz"));    
msg.setFrom(new InternetAddress("jjjj@kkkk.com", "hhh"));  
BodyPart messageBodyPart = new MimeBodyPart();  
messageBodyPart.setText("this is a test email");

Transport.send(msg);  

Now if I deploy my app without the mail.jar dependency, when the class that contains this code is loaded I get a 现在,如果我部署没有mail.jar依赖项的应用程序,则在加载包含此代码的类时,我会得到一个

ClassNotFoundException: javax.mail.Message, meaning mail.jar is not in the classpath.

If I place mail.jar into domain/lib folder or just add a classpath entry into my app's manifest including the location of mail.jar, I no longer have the ClassNotFoundException , but when the lookup is executed and I retrieve the Session, I get the weirdest 如果我将mail.jar放到domain / lib文件夹中,或者只是将一个类路径条目添加到我的应用程序清单中,包括mail.jar的位置,则不再具有ClassNotFoundException ,但是当执行查找并检索Session时,我得到了最古怪的

ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session.

This would mean that I have two versions of mail.jar, but as I said if I remove it from /lib or dont add the classpath entry to the manifest it doesnt even find one. 这意味着我有两个版本的mail.jar,但是正如我所说的,如果我从/ lib中删除它或不将classpath条目添加到清单中,它甚至找不到一个。

I'm on Ubuntu 11.10 , using Glassfish 3.1.1 and java-6-sun-1.6.0.26 (so activation.jar is not the problem). 我在使用Glassfish 3.1.1java-6-sun-1.6.0.26的 Ubuntu 11.10上(因此,activation.jar不是问题)。 Any idea will be much appreciated, as I can't think of anything else. 任何想法都将不胜感激,因为我别无其他。

JavaMail (all the javax.mail.* classes) is included in GlassFish (assuming you're using the full Java EE platform version and not just the Web Profile version); JavaMail(所有javax.mail。*类)都包含在GlassFish中(假设您使用的是完整的Java EE平台版本,而不仅仅是Web Profile版本); you shouldn't need to include mail.jar in your application or install it manually. 您不需要在应用程序中包含mail.jar或手动安装它。 I can't explain why javax.mail.Message isn't found when you do that. 我无法解释为什么这样做时找不到javax.mail.Message。 The ClassCastException indicates that you have two versions of mail.jar available to the application. ClassCastException指示您对应用程序有两个版本的mail.jar。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Glassfish上部署的Web应用程序上的XML解析错误 - XML parsing on a web application deployed on Glassfish error 从Glassfish 2.1迁移到Glassfish 4.1后,无法发送电子邮件 - Failed to send an email after migration from Glassfish 2.1 to Glassfish 4.1 rich:dataScroller在Glassfish 3.0.1中部署应用程序时无法正常工作 - rich:dataScroller not working properly when application is deployed in glassfish 3.0.1 在glassFish中运行已部署的JSP应用程序时出现错误PWC6345 - Error PWC6345 on running deployed JSP application in glassFish 是否可以从桌面应用程序访问在glassfish上部署的servlet? - Is it possible to access a servlet deployed on glassfish from a desktop application? 从IntelliJ Idea 2018.1到Glassfish 5.0.1的应用程序未部署 - The application from IntelliJ Idea 2018.1 to Glassfish 5.0.1 is not deployed 配置IntelliJ 14调试外部部署的Glassfish应用程序 - Configuring IntelliJ 14 to debug an externally deployed Glassfish application 应用程序已在GlassFish 4.1上成功部署,但浏览错误404 - Application Deployed Successful on GlassFish 4.1 but browsing error 404 从我在Glassfish服务器中部署的应用程序调用Web服务时出现ArrayIndexOutOfBoundsException - ArrayIndexOutOfBoundsException when invoking webservice from my application deployed in glassfish server 如何通过Glassfish中已部署的应用程序定义其他连接池 - How to define a different connection pool by deployed application in glassfish
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM