Hi
from a unit test, I am trying to get the mail session declared in
tomee.xml via JNDI
<Resource id="myMailSession" type="javax.mail.Session">
mail.smtp.host=localhost
mail.smtp.port=9025
mail.transport.protocol=smtp
mail.smtp.user=xxx@localhost
mail.smtp.auth=true
mail.smtp.password=xxx
</Resource>
final Context context =
EJBContainer.createEJBContainer().getContext();
javax.mail.Session session = (javax.mail.Session)
context.lookup("java:comp/env/myMailSession");
final Context context =
EJBContainer.createEJBContainer().getContext();
javax.mail.Session session = (javax.mail.Session)
context.lookup("java:global/myMailSession");
final Context context =
EJBContainer.createEJBContainer().getContext();
javax.mail.Session session = (javax.mail.Session)
context.lookup("java:openejb/Resource/myMailSession");
none of these works :-(
but no problem, I've put the mail session into an EJB and then
final Context context = EJBContainer.createEJBContainer().getContext();
EmailEJB email = (EmailEJB) context
.lookup("java:global/myEclipseApp/"+EmailEJB.class.getSimpleName());
where
@Singleton
public class EmailEJB {
@Resource(name="myMailSession")
private javax.mail.Session session;
public void send(String to, String from, String subject, String body,
byte[] data)
throws IOException {...}
ok, now I have the MailSession
but, then, this mail session seems not to be the one I am looking for,
because its properties come empty. For example I was expecting
boolean authenticate = "true".equals(session
.getProperty("mail.smtp.auth"));
to be true, not null...
in fact, in its properties, it has this
ServiceId=Default Mail Session
looks like I am missing several things here :-) I just thought since I
was using
@Resource(name="myMailSession")
the resource I was looking for was that one declared at tomee.xml
any help is welcome
TIA
Leo