- JBoss 7.2
- eclipse to travel a project
- a transportation service server, tin hold upwardly gmail
Configure Mail datasource inwards JBoss 7.2
- Open standalone.xml
- Search for the transportation service subsystem
<subsystem xmlns="urn:jboss:domain:mail:1.1"></subsystem>
- 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>
- 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
0 komentar:
Please comment if there are any that need to be asked.