2
我设置邮件资源定义在我的context.xmljavax.naming.NameNotFoundException:无法找到邮件
<Resource
name="MyMailSession"
auth="Container"
type="javax.mail.Session"
mail.smtp.sendpartial="true"
mail.debug="true"
mail.smtp.host="myhost.hosting.com"
/>
和邮件工具,它会查找邮件会话的JNDI:
public int send() throws Exception {
int msgCount = 0; //number of recipients
Context ctx = new InitialContext();
Session session = (Session) ctx.lookup("java:comp/env/mail/MyMailSession");
MimeMessage message = new MimeMessage(session);
但我收到以下异常:
javax.naming.NameNotFoundException: Name [mail/MyMailSession] is not bound in this Context. Unable to find [mail].
at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
...
是作为前缀的资源名称所必需的邮件标签,当谈到邮寄还是更具约定? (即查找用户事务将被设置为的Java:比较/ UserTransaction的)
我更想知道'mail'前缀是否必要,事实证明它不是。尽管如此,正确答案 – 2014-10-17 01:03:10