javax.mail.AuthenticationFailedException
2008-06-13 11:44
393 查看
当今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发信的用法相似,在此不累述。 |
相关文章推荐
- javax.mail.AuthenticationFailedException异常的处理
- javax.mail.AuthenticationFailedException: 550
- javax.mail.AuthenticationFailedException
- JavaMail发邮件失败:javax.mail.AuthenticationFailedException: 550 ???§±????¨
- javax.mail.AuthenticationFailedException: 550
- javax.mail.AuthenticationFailedException: 535 Error: authentication failed的解决办法
- javax.mail.AuthenticationFailedException
- javax.mail.AuthenticationFailedException: 535 Error: authentication failed
- javax.mail.AuthenticationFailedException异常一个让你想不到的原因
- javax.mail.AuthenticationFailedException 的解决方案
- java mail: javax.mail.AuthenticationFailedException: 535 authentication failed
- javax.mail.AuthenticationFailedException:
- javax.mail.AuthenticationFailedException
- javax.mail.AuthenticationFailedException: 535 Error: authentication failed
- javax.mail.AuthenticationFailedException
- 发送邮件Javax.mail.AuthenticationFailedException: 530 Error:
- javax.mail.AuthenticationFailedException异常的处理
- javax.mail.AuthenticationFailedException: 550 User has no permission出错
- javax.mail.AuthenticationFailedException异常的处理
- javax.mail.AuthenticationFailedException异常