天空是蓝色的

做好软件为中国 #gcc -c helloworld.c -o helloworld.o //编译目标文件 #gcc helloworld.o -o helloworld //编译成可执行exe #helloworld //运行exe
数据加载中……
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 设计规范中指定的。





posted on 2005-12-13 15:54 bluesky 阅读(2697) 评论(2)  编辑  收藏 所属分类: 工作总结

评论

# re: Weblogic-JNDI-MailSession-javaMail-java.io.NotSerializableException: javax.mail.Session 2011-09-27 20:07 Penny

This is because the MailSession returned from the lookup is not serializable and thus you will get NULL from the lookup.

Do the lookup the MailSession locally and you will solve the problem.
  回复  更多评论    

# re: Weblogic-JNDI-MailSession-javaMail-java.io.NotSerializableException: javax.mail.Session 2011-10-14 13:59 Term Papers

Very interesting ideas! I’ll be back for your new articles!
  回复  更多评论    

只有注册用户登录后才能发表评论。


网站导航: