Hi Thiago,

maybe i give to less informations.

Am 11.09.18 um 14:13 schrieb Thiago H. de Paula Figueiredo:
On Sun, Sep 9, 2018 at 12:22 PM Andreas Ernst <a...@ae-online.de> wrote:

Hi,


Hi!


i try to access a Payara Mailsession (mail-resource), but it is always
null:

@Stateless
public class MailSessionBean {

    private static final Logger logger =
Logger.getLogger(MailSessionBean.class.getName());
    @Resource(name = "mail/motdSession")
    private Session mailSession;


Shouldn't you use @Inject instead of @Resource? What's the fully qualified
name of the @Stateless and @Resource annotations you're using?

This is the bean, where mail is created:

@Stateless
public class MailSessionBean {

private static final Logger logger = Logger.getLogger(MailSessionBean.class.getName());
  @Resource(lookup = "mail/motdSession")
  private Session mailSession;

  public void sendEmail(String to, String subject, String body) {
    MimeMessage message = new MimeMessage(mailSession);
    try {
message.setFrom(new InternetAddress(mailSession.getProperty("mail.from")));
      InternetAddress[] address = {new InternetAddress(to)};
      message.setRecipients(Message.RecipientType.TO, address);
      message.setSubject(subject);
      message.setSentDate(new Date());
      message.setText(body);
      Transport.send(message);
    } catch (MessagingException ex) {
    }
  }
}

Here is the Tapestry page:

import de.aeits.motd.beans.MailSessionBean;
[...]

public class AccountReset {

  [...]
  @Inject
  private MailSessionBean mailBean;

  [...]

  Object onSuccess() {
mailBean.sendEmail("i...@ae-online.de", "TestMail - Java Mail Session", "TestMail - Java Mail Session - Body\n\n(c) 2018 AE Online");
  }

  [...]
}


mail:~ # asadmin list-javamail-resources
Enter admin user name>
Enter admin password>
mail/Session
mailSession
mail/motdSession
Command list-javamail-resources executed successfully.

--
ae | Andreas Ernst | IT Spektrum
Postfach 5, 65612 Beselich
Schupbacher Str. 32, 65614 Beselich, Germany
Tel: +49-6484-91002 Fax: +49-6484-91003
a...@ae-online.de | www.ae-online.de
www.tachyon-online.de

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to