I noticed to this point but if he wanna send mail with pure java he can use JavaMail API like this :
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.*;
public class MailSender {
public void postMail(String smtpsrv, String recipients[], String subject,
String message, String from) throws MessagingException {
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", smtpsrv);
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress addressTo[]= new InternetAddress[recipients.length];
addressTo= new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo= new InternetAddress(recipients);
}
msg.setRecipients(Message.RecipientType.TO,addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/html;charset=utf-8");
Transport.send(msg);
}
}
But if he has Application Server , he could use application Server Mail Configuration to send mail
automatically also Web Server like : JBossMail, ...
And also to use AOP Concept to send mail he can use AspectJ, AspectWerks and JBossAOP too.