【问题标题】:Sent e-mail Using jsp [duplicate]使用jsp发送电子邮件[重复]
【发布时间】:2012-12-17 05:59:00
【问题描述】:

可能重复:
how to send an email from jsp/servlet?

是否可以使用 jsp 页面从一个邮件 ID 向其他邮件 ID 发送电子邮件? 我开发了一个投诉管理系统,用户可以通过提供详细信息来提交投诉,然后生成投诉编号。但我需要确保用户提供正确的电子邮件 ID。

所以我想将投诉号码发送到用户在表单中输入的电子邮件 ID。我不知道如何使用 jsp 向 id 发送邮件,我已经用谷歌搜索过,但不幸的是没有找到任何有用的解决方案。我正在使用 jsp 和 java 来开发应用程序。

如果有人可以帮助我,我将不胜感激,我为糟糕的写作道歉。

【问题讨论】:

    标签: jsp


    【解决方案1】:

    试试这个:

    <%@ taglib uri="http://jakarta.apache.org/taglibs/mailer-1.1" prefix="mt" %>
    <mt:mail session="java:/comp/env/mail/Session" to="foo@home.net" from="registration@mydomain.de" subject="Registration Confirmation">
        <mt:message type="html"><h1>Perfect</h1>Super</mt:message>
        <mt:send/>
    </mt:mail>
    

    因此您的 /META-INF/context.xml 必须包含:

    <?xml version='1.0' encoding='utf-8'?>
    <Context>
      <Resource name="mail/Session" 
         auth="Container"
         type="javax.mail.Session"
         username="webmaster@mydomain.de"
         password="password"
         mail.debug="true"
         mail.user="webmaster@mydomain.de"
         mail.from="registration@mydomain.de"
         mail.transport.protocol="smtp"
         mail.smtp.host="smtp.strato.de"
         mail.smtp.auth="true"/>
    </Context>
    

    并且/WEB-INF/web.xml必须包含:

    ...
        <resource-ref>
           <res-ref-name>mail/Session</res-ref-name>
            <res-type>javax.mail.Session</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>
    </web>
    

    注意: 如果不存在,context.xml 将被复制到 jboss-server 中。就是这样,应用服务器不同的环境配置(live、test、staging)。

    注意: 您需要在您的 tomcat/lib 目录中的 mail.jar、mailer-1.1.jar 和 mail-1.4.4.jar(因为即使不再部署应用程序,context.xml 也将可用。)

    【讨论】:

    • 顺便说一句,您应该将服务器配置为提供 jndi-mailing-resources。
    • 谢谢 Peter,您能否告诉我如何配置服务器以提供 jndi-mailing-resources。
    • 您使用的是什么服务器?雄猫?老板?玻璃鱼?
    猜你喜欢
    • 2011-11-20
    • 2020-04-24
    • 2012-03-22
    • 2015-12-10
    • 2015-09-30
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    相关资源
    最近更新 更多