J'ai une application web sur JBoss 4.2.3 et j'aimerais l'envoyer par e-mail. Je pourrais faire quelque chose comme:Méthode recommandée pour envoyer un e-mail à partir d'une application Web?
try {
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable","false");
props.put("mail.smtp.host","smtp.somehost.com");
props.put("mail.smtp.auth", "true");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
// -- Create a new message --
Message msg = new MimeMessage(session);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress("[email protected]"));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[email protected]", false));
msg.setSubject("yadayada");
msg.setText("Yada yada");
// -- Set some other header information --
msg.setHeader("MyMail", "Mr. XYZ");
msg.setSentDate(new Date());
// -- Send the message --
Transport.send(msg);
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("Exception "+ex);
}
mais il ne se sent pas bien. Cette échelle va-t-elle?