2012-06-28 124 views
3

我正在使用jboss 7.1.1並希望使用JavaMail發送電子郵件。我嘗試了以下配置,但出現錯誤。是否有人使用Jboss 7.1.1配置了gmail?在jboss中配置gmail 7.1.1

<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 [email protected]" password="mypass"/> 
      </smtp-server> 

     </mail-session> 

</subsystem> 
+1

請與我們分享那個邪惡的錯誤:-) – David

回答

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="[email protected]" password="myPasswordInGmail"/> 
       </smtp-server> 
      </mail-session> 
</subsystem> 

提示:

  • 名稱必須包含完整的電子郵件地址,以@ gmail.com

  • SMTP服務器必須設置標誌SSL = 「真」

[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 
} 
+0

怎麼樣TLS? – jacktrades

+0

在子系統/ AS7/WildFly 的更高版本中添加了對TLS的支持,您需要做的是在服務器配置中使用TLS端口和tls = true – ctomc