Tomcat 6 Javax.mail 会话 envCtx.lookup(“mail/Session”) 不返回

发布于 2024-10-29 09:43:49 字数 1030 浏览 2 评论 0原文

我正在使用 Tomcat 6 通过 Javax.mail API 发送电子邮件客户端,我在 server.xml 中设置了我的配置

<Resource name="mail/Session" auth="Container"
            type="javax.mail.Session"
            mail.smtp.host="localhost"/>

,如下所示 在我的 web.xml 中

<resource-ref>
    <description>Resource reference to a container-managed JNDI JavaMail factory for sending e-mails.</description>
    <res-ref-name>mail/Session</res-ref-name>
    <res-type>javax.mail.Session</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

设置如下但是当我尝试创建邮件会话时...使用上下文。查找

ontext initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            *mailSession = (Session)envCtx.lookup("mail/Session");*

调用 nvCtx.lookup("mail/Session");没有返回......它会在 org/springframework/jms/listener/DefaultMessageListenerContainer 中中断......

任何线索...... 我很感激任何帮助。

谢谢 维杰

I am using Tomcat 6 to send a email client with Javax.mail APIs , i set up my configurations in server.xml as below

<Resource name="mail/Session" auth="Container"
            type="javax.mail.Session"
            mail.smtp.host="localhost"/>

And in my web.xml as below

<resource-ref>
    <description>Resource reference to a container-managed JNDI JavaMail factory for sending e-mails.</description>
    <res-ref-name>mail/Session</res-ref-name>
    <res-type>javax.mail.Session</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

But when i tried to create a mail Session ...using context.lookup

ontext initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            *mailSession = (Session)envCtx.lookup("mail/Session");*

The call nvCtx.lookup("mail/Session"); is not returning....it goes and break in org/springframework/jms/listener/DefaultMessageListenerContainer ...

Any Clues ....
I appreciate any help.

Thanks
Vijay

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

找回味觉 2024-11-05 09:43:49

由于您不使用 spring 使用此:

来源: Apache Tomcat 6.0 文档 - JDNI 资源

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session session = (Session) envCtx.lookup("mail/Session");

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(request.getParameter("from")));
InternetAddress to[] = new InternetAddress[1];
to[0] = new InternetAddress(request.getParameter("to"));
message.setRecipients(Message.RecipientType.TO, to);
message.setSubject(request.getParameter("subject"));
message.setContent(request.getParameter("content"), "text/plain");
Transport.send(message);

As you don't use spring use this:

Source: Apache Tomcat 6.0 Documentation - JDNI Resources

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session session = (Session) envCtx.lookup("mail/Session");

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(request.getParameter("from")));
InternetAddress to[] = new InternetAddress[1];
to[0] = new InternetAddress(request.getParameter("to"));
message.setRecipients(Message.RecipientType.TO, to);
message.setSubject(request.getParameter("subject"));
message.setContent(request.getParameter("content"), "text/plain");
Transport.send(message);
不一样的天空 2024-11-05 09:43:49

您的配置看起来不错,可能您需要先清理服务器(如果您使用 eclipse)。

无论如何:如果你使用 spring 那么你可以使用 spring Framwork 来访问 JNDI 资源:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/jee
    http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">

    <jee:jndi-lookup id="jndiEmailSession"
         jndi-name="java:comp/env/email/Session" />
</beans>

Your configuration looks ok, may you need to clean the server first (if you use eclipse).

Anyway: If you use spring then you can use the spring Framwork to access the JNDI ressource:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/jee
    http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">

    <jee:jndi-lookup id="jndiEmailSession"
         jndi-name="java:comp/env/email/Session" />
</beans>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文