How To Configure Postal Service Resources Inward Jboss 7.2 Amongst A Sample Coffee Client

This tutorial assumes that you lot convey the next installed on your local system:

  1. JBoss 7.2
  2. eclipse to travel a project
  3. a transportation service server, tin hold upwardly gmail
In this page nosotros volition summarize how to configure a transportation service dataSource inwards Jboss together with exercise a JavaEE6 customer to transportation a sample email.

Configure Mail datasource inwards JBoss 7.2

  1. Open standalone.xml
  2. Search for the transportation service subsystem
    <subsystem xmlns="urn:jboss:domain:mail:1.1"></subsystem>
  3. Define a transportation service session
    <mail-session jndi-name="java:/czetsuyaMail">  <smtp-server outbound-socket-binding-ref="mail-smtp">   <login name="username@xxx.com" password="secret"/>  </smtp-server> </mail-session> 
  4. Define an outbound socket nosotros volition exercise 2: smtp amongst port 587 (eg zimbra) together with ssl amongst port 465 (for gmail). Search for socket-binding-group department together with add together the next lines: for Zimbra
    <outbound-socket-binding name="mail-smtp">  <remote-destination host="yourServer.net" port="587"/> </outbound-socket-binding> 
    OR for gmail
    <outbound-socket-binding name="mail-smtp-gmail">  <remote-destination host="yourServer.com" port="465"/> </outbound-socket-binding> 

Sample Client
package org.czetsuya.test;  import java.util.Date;  import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.ejb.Asynchronous; import javax.ejb.Singleton; import javax.ejb.Startup; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage.RecipientType;  @Startup @Singleton world shape MailService {  @Resource(lookup = "java:/czetsuyaMail")  mortal Session mailSession;   @PostConstruct  mortal void init() throws AddressException, MessagingException {   sendAsyncMessage("Test");  }   @Asynchronous  mortal void sendAsyncMessage(String htmlMessage) throws AddressException,    MessagingException {    MimeMessage msg = novel MimeMessage(mailSession);   msg.setFrom(new InternetAddress("spamMeNot@gmail.com"));   msg.setSubject("Test");   msg.setSentDate(new Date());   msg.setContent(htmlMessage, "text/html");    msg.setRecipient(RecipientType.TO, novel InternetAddress(     "spamMeNot@gmail.com"));   InternetAddress[] replytoAddress = { novel InternetAddress(     "spamMeNot@gmail.com") };   msg.setReplyTo(replytoAddress);    Transport.send(msg);  } } 

You tin genuinely exam amongst telnet if your port is opened upwardly yesteryear executing this dominance inwards dominance prompt:
telnet server port 

Reference:
https://community.jboss.org/wiki/JBossAS720EmailSessionConfigurtion-EnglishVersion
http://commons.apache.org/proper/commons-email/userguide.html
Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.