Weblogic-JNDI-MailSession-javaMail-java.io.NotSerializableException: javax.mail.Session

import java.util.Properties;

import javax.mail.Session;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class SendMail {
    Context ic = null;

    public SendMail() {
    }

    private Properties props;

    public void send() throws Exception {

        // 使用JNDI查询Mail Session
        try {

            /*
             * Hashtable ht = new Hashtable();
             * ht.put(Context.INITIAL_CONTEXT_FACTORY,
             * “weblogic.jndi.WLInitialContextFactory”);
             * ht.put(Context.PROVIDER_URL, “t3://localhost:7001/slide/”); ic =
             * new InitialContext(ht);
             */
            ic = getInitialContext();
            Session session = (Session) ic.lookup(“mail/MailSession”);

        } catch (NamingException e) {
            e.printStackTrace();
        }

    }

    public static void main(String args[]) throws Exception {
        SendMail sendMail = new SendMail();
        sendMail.send();
        System.out.println(“send ok”);
    }

    public Context getInitialContext() throws Exception {
        String url = “t3://localhost:7001”;
        String user = “weblogic”;
        String password = “weblogic”;
        Properties properties = null;
        try {
            properties = new Properties();
            properties.put(Context.INITIAL_CONTEXT_FACTORY,
                    “weblogic.jndi.WLInitialContextFactory”);
            properties.put(Context.PROVIDER_URL, url);
            if (user != null) {
                properties.put(Context.SECURITY_PRINCIPAL, user);
                properties.put(Context.SECURITY_CREDENTIALS,
                        password == null ? “” : password);
            }

            return new InitialContext(properties);
        } catch (Exception e) {
            throw e;
        }
    }

}

java.io.NotSerializableException: javax.mail.Session]

相关帖子

http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=122&threadID=10958&tstart=1112

http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=121&threadID=27136&tstart=15

http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=1&threadID=1450&tstart=1440

weblogic配置

服务-邮件-在此页中,您可以定义此邮件会话的配置。

名称:MyMailSession
JNDI 名称:mail/MailSession
属性:
mail.debug=true
mail.smtp.port=25
mail.smtp.auth=true
mail.smtp.host=192.168.8.1

用来配置此邮件会话的属性。这些属性名是在 JavaMail API 设计规范中指定的。

原创文章,转载请注明: 转载自海波无痕

本文链接地址: Weblogic-JNDI-MailSession-javaMail-java.io.NotSerializableException: javax.mail.Session

文章的脚注信息由WordPress的wp-posturl插件自动生成

此条目发表在javaee分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

评论链接可以 移除 nofollow.