Actually the code above check if the mailFrom argument is null.

If it's null it recovers from the mail-service.xml

public class SendMail {
  |     
  | public static Session newMailSession()     {
  |  try {
  |     Object ctx = new InitialContext().lookup("java:/Mail");
  | 
  |     return (Session)PortableRemoteObject.narrow(ctx, Session.class);
  |     } catch (javax.naming.NamingException e) {
  |         e.printStackTrace();
  |         return null;
  |     }
  | }
  |     
  | public static void sendMessage(String mailFrom, String mailTo, String 
subject, String msg, boolean htmlText) 
  | {
  |         try
  |         {
  |            Session session = newMailSession();
  |            Message message = new MimeMessage(session);
  |                 
  |            if (mailFrom == null)
  |                     mailFrom = session.getProperty("mail.from");           
message.setFrom( new InternetAddress(mailFrom));
  | 
  |            InternetAddress to[] = new InternetAddress[1];
  |            to[0] = new InternetAddress(mailTo);
  |            message.setRecipients(Message.RecipientType.TO, to);
  |            message.setSubject(subject);
  |            message.setSentDate(new Date());
  |             
  |            String textType;
  |            if (htmlText)
  |                   textType = "text/html";
  |            else textType = "text/plain";
  |            message.setContent(msg, textType);
  |             
  |            Transport trans = session.getTransport("smtp");
  |             
  |            trans.connect(session.getProperty("mail.smtp.host"), 
  |             session.getProperty("mail.smtp.user"),
  |             session.getProperty("mail.smtp.password"));
  |            trans.sendMessage(message, message.getAllRecipients());
  |            trans.close();
  |            }
  |            catch (Exception e)
  |            {
  |                 e.printStackTrace();
  |             }
  | }

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4010639#4010639

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4010639
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to