3

我正在使用 jboss 7.1.1 并想使用 JavaMail 发送电子邮件。我尝试了以下配置但出现错误。有人用 Jboss 7.1.1 配置了 gmail 吗?

 <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
    <socket-binding name="management-native" interface="management" port="${jboss.management.native.port:9999}"/>
    <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
    <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9443}"/>
    <socket-binding name="ajp" port="8009"/>
    <socket-binding name="http" port="8080"/>
    <socket-binding name="https" port="8443"/>
    <socket-binding name="jacorb" interface="unsecure" port="3528"/>
    <socket-binding name="jacorb-ssl" interface="unsecure" port="3529"/>
    <socket-binding name="messaging" port="5445"/>
    <socket-binding name="messaging-throughput" port="5455"/>
    <socket-binding name="osgi-http" interface="management" port="8090"/>
    <socket-binding name="remoting" port="4447"/>
    <socket-binding name="txn-recovery-environment" port="4712"/>
    <socket-binding name="txn-status-manager" port="4713"/>
    <outbound-socket-binding name="mail-smtp">
        <remote-destination host="localhost" port="25"/>
    </outbound-socket-binding>
    <outbound-socket-binding name="mail-smtp-gmail">
        <remote-destination host="smtp.googlemail.com" port="587"/>
    </outbound-socket-binding>
</socket-binding-group>

这是邮件配置

<subsystem xmlns="urn:jboss:domain:mail:1.0">
        <mail-session jndi-name="java:jboss/mail/Default">
            <smtp-server outbound-socket-binding-ref="mail-smtp"/>
        </mail-session>

         <mail-session jndi-name="java:jboss/mail/TestGmail">
            <smtp-server outbound-socket-binding-ref="mail-smtp-gmail">
                <login name=mymail@gmail.com" password="mypass"/>
            </smtp-server>

        </mail-session>

</subsystem>
4

1 回答 1

7

使用 JBoss 7.1 发送电子邮件的有效配置:

[1] 在部分子系统中:邮件->

<subsystem xmlns="urn:jboss:domain:mail:1.0">
<mail-session jndi-name="java:jboss/mail/SampleMS_With_GmailUser">
                <smtp-server ssl="true" outbound-socket-binding-ref="mail-gmail-smtp">
                    <login name="myemailingmail@gmail.com" password="myPasswordInGmail"/>
                </smtp-server>
            </mail-session>
</subsystem>

注意:

  • 名称必须包含完整的电子邮件地址,并带有@gmail.com

  • smtp-server 必须设置标志 ssl="true"

[2] 在 socket-binding-group 部分 ->

<socket-binding-group ....>
        <outbound-socket-binding name="mail-gmail-smtp">
            <remote-destination host="smtp.gmail.com" port="465"/>
        </outbound-socket-binding>
</socket-binding-group>

就这样。然后你可以在 servlet 中使用它:

@WebServlet(urlPatterns = "/servlets/public/SendEmailTestServlet")
public class SendEmailTestServlet extends HttpServlet {

    @Resource(mappedName = "java:jboss/mail/SampleMS_With_GmailUser")
    javax.mail.Session mailSession;

        // use of mailSession
}
于 2012-10-18T11:21:25.020 回答