[jboss-user] [Beginners Corner] - Re: Problem with sending Email from jBoss

j-n00b do-not-reply at jboss.com
Wed Jan 21 09:37:31 EST 2009


Hi!

In one of my lasts projects I wrote an MDB, which reads text messages from a queue and sends mails to some my mail account. Maybe this helps you a little.


First of all, you have to set up the JBoss mail service in server//deploy/mail-service.xml. You need to specify the connection properties to the mail server which is used. 


Secondly you write the code to send a mail, for example:

// who should receive the mail
  | Address[] to = InternetAddress.parse("duke at java.sun.com,homer at simpson.net", false);
  | 
  | // create a simple text message
  | javax.mail.Message message = new MimeMessage(session);
  | message.setFrom(); 
  | message.setRecipients(javax.mail.Message.RecipientType.TO, to);
  | message.setSubject("Mail subject goes here");
  | message.setSentDate(new Date());
  | message.setText("java mail rocks!");
  | 
  | // ... and send it
  | Transport.send(message);

That's it it :-) If you do not specify the "from" property, the default value defined in mail-service.xml is used.

Hope that helped! Keep asking, if you have any problems.

cheers,
Andre

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

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4203659



More information about the jboss-user mailing list