The JEE application server must provide an email resource. The only thing you need to do is find the resource (I believe it is configured) and send an email.
//Mail Resource injection not working on wildfly 10 //@Resource(lookup = "java:/futuramail") private Session mailSession; @Asynchronous @Lock(LockType.READ) public void sendMail(String recipient, String subject, String text) { try { InitialContext ic = new InitialContext(); mailSession = (Session) ic.lookup("java:/futuramail"); MimeMessage message = new MimeMessage(mailSession); Address[] to = new InternetAddress[]{new InternetAddress(recipient)}; message.setRecipients(Message.RecipientType.TO, to); message.setSubject(subject); message.setSentDate(new Date()); message.setContent(text, "text/html"); //message.setText(text); Transport.send(message); System.out.println("mail sent"); } catch (MessagingException me) { me.printStackTrace(); } catch (NamingException ex) { Logger.getLogger(MailProcessor.class.getName()).log(Level.SEVERE, null, ex); } }
Bruno_Condemi
source share