How to configuration javamail with jboss 7.1.1final
samwun9988 Dec 15, 2012 9:28 AMHi, with jboss 7.1.1.final, I am not able to send email through a remote smtp server.
Here is my module.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="javax.activation.api">
<dependencies>
<module name="javax.api" />
<module name="javax.mail.api" >
<imports><include path="META-INF"/></imports>
</module>
</dependencies>
<resources>
<resource-root path="activation-1.1.1.jar"/>
<!-- Insert resources here -->
</resources>
</module>
My java client code:
package LuxuryLiving.utils;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class SendMail {
private String from;
private String to;
private String subject;
private String text;
public SendMail(String from, String to, String subject, String text){
this.from = from;
this.to = to;
this.subject = subject;
this.text = text;
}
public void send() throws NamingException{
// Context initCtx = new InitialContext();
//javax.mail.Session session = (Session) initCtx.lookup("java:/Mail/Default");
//
//String transportProtocol = session.getProperty("mail.transport.protocol");
//String mailServer = session.getProperty("mail.smtp.host");
//String mailUser = session.getProperty("mail.smtp.user");
Properties props = new Properties();
props.put("mail.smtp.host", "smtp-auth.no-ip.com");
props.put("mail.smtp.port", "587");
props.setProperty("mail.user", "xxx@no-ipdomain.com.au");
props.setProperty("mail.password", "mypass");
Session mailSession = Session.getDefaultInstance(props);
Message simpleMessage = new MimeMessage(mailSession);
InternetAddress fromAddress = null;
InternetAddress toAddress = null;
try {
fromAddress = new InternetAddress(from);
toAddress = new InternetAddress(to);
} catch (AddressException e) {
// TODO Auto-generated catch block
throw new RuntimeException(e);
}
try {
simpleMessage.setFrom(fromAddress);
simpleMessage.setRecipient(RecipientType.TO, toAddress);
simpleMessage.setSubject(subject);
simpleMessage.setText(text);
Transport.send(simpleMessage);
} catch (MessagingException e) {
// TODO Auto-generated catch block
throw new RuntimeException(e);
}
}
}
What I have missing ?
Any suggestion is very appreciated.
Thanks
Sam