Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java EE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
话题被移动
该话题已被移动 - why , 2003-06-28 19:33
如果您尚不清楚该话题被移动的原因,请参考论坛规则以及本版公告或者联系本版版主。
作者 Re:请教高手,我的程序哪有问题? 谢 [Re:fatboy2]
nothing

天外飞仙.....

CJSDN高级会员


发贴: 1636
积分: 131
于 2003-05-24 22:22 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
用javamail进行认证发信 阅读次数4016

出处 CN-JAVA原创:net.fan



[中文JAVA技术网 2002-04-08]

当今mail服务器大多都是通过认证才能发信的,现在的网上介绍javamail发信的文章都没有深入到有关认证的方面,除非自己装一个open relay的mail服务器,但是这样有很危险,本人根据自己工作中用的javamail的方法说一下自己的用法,不对的地方请大家多指教.
  首先设置属性Properties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth","true");注意的是此处必须加上true要不然stmp连接的时候不会认证
  用Authenticator写认证类下面是本人的认证类
package org.xxx;
import javax.mail.*;
import javax.mail.internet.*;
public class PopupAuthenticator extends Authenticator{
String username=null;
String password=null;
public PopupAuthenticator(){}
public PasswordAuthentication performCheck(String user,String pass){
username = user;
password = pass;
return getPasswordAuthentication();
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}

}
认证类写完后,在发信的程序中加上
PasswordAuthentication pop = popAuthenticator.performCheck(username,password);
Session mysession=Session.getInstance(props,popAuthenticator);
mailsession加的popAuthenticator
其他的方法和javamail发信的用法相似,在此不累述。




躲得过的怪物,躲不过的刺激


话题树型展开
人气 标题 作者 字数 发贴时间
10679 请教高手,我的程序哪有问题? 谢 (JavaMail SMTP 发信权限验证) fatboy2 3504 2003-05-24 10:29
14823 Re:请教高手,我的程序哪有问题? 谢 nothing 86 2003-05-24 10:35
9393 Re:请教高手,我的程序哪有问题? 谢 fatboy2 59 2003-05-24 10:40
9344 Re:请教高手,我的程序哪有问题? 谢 fatboy2 61 2003-05-24 11:28
9470 Re:请教高手,我的程序哪有问题? 谢 why 66 2003-05-24 11:34
9367 Re:请教高手,我的程序哪有问题? 谢 fatboy2 79 2003-05-24 11:39
11370 Re:请教高手,我的程序哪有问题? 谢 nothing 41 2003-05-24 11:45
9321 Re:请教高手,我的程序哪有问题? 谢 fatboy2 41 2003-05-24 11:49
9285 Re:请教高手,我的程序哪有问题? 谢 fatboy2 110 2003-05-24 13:16
11327 Re:请教高手,我的程序哪有问题? 谢 nothing 1136 2003-05-24 22:22
9728 Re:请教高手,我的程序哪有问题? 谢 chenyajun5 13 2003-06-02 22:07

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923