jmail中smtp验证问题?

xiaoxiao1987918 2008-07-10 05:39:03
我用公司的用户名在公司的企业邮局里可以任意的发邮件,可是用"smtp.163.com"或者其他的就不可以发了。而且还出了个异常
java.lang.SecurityException:Access to default session denied

请问各位高手,这是咋回事啊?(163的用户名和密码都是正确的)
...全文
201 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
victor_woo 2008-07-11
  • 打赏
  • 举报
回复
我看了自己的代码,我用的是m_objSession = Session.getInstance(m_properties,m_objAuthenticator);
其他一模一样,呵呵

好久没有用了,刚刚试一下,还可以发出去

我的是126的邮箱
xiaoxiao1987918 2008-07-11
  • 打赏
  • 举报
回复
围绕我几天的问题解决了!!!呵呵

不是代码的问题,是 server的问题,把weblogic 服务重启一次就可以发了!
xiaoxiao1987918 2008-07-11
  • 打赏
  • 举报
回复

有谁能帮我看看代码,还有哪里没注意到的???


//身份验证类
package com.rlis.model;

import javax.mail.PasswordAuthentication;

/**
* Eway邮件认证信息
*
*/
public class EwayAuthenticator extends javax.mail.Authenticator {
private String account; //帐号
private String password; //密码

/**
* 构造函数赋值
* @param user 帐号
* @param password 密码
*/
public EwayAuthenticator(String user, String password) {
this.account = user;
this.password = password;
}

protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(account, password);
}

/**
* @return the account
*/
public String getAccount() {
return account;
}

/**
* @return the password
*/
public String getPassword() {
return password;
}
}
//发送邮件方法
public boolean sendEmail(String smtpServer, EwayAuthenticator authenticator, EmailInfo emailInfo)
throws UserException
{
logger.info("Sendinging email message: (fromAddress:"+authenticator.getAccount()+"," +
"toAddress:"+((InternetAddress)emailInfo.getToAddresses()[0]).getAddress()+")");
boolean returnResult = false;
Properties props = System.getProperties();
try {
props.put("mail.smtp.host", "stmp.sina.com");
props.put("mail.smtp.port", 25);

// Get session
props.put("mail.smtp.auth", "true"); // 这样才能通过验证

EwayAuthenticator myauth = new EwayAuthenticator(authenticator.getAccount(),authenticator.getPassword());
Session session = Session.getDefaultInstance(props, myauth);

Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(authenticator.getAccount()));
msg.setRecipients(javax.mail.Message.RecipientType.TO, emailInfo.getToAddresses());
msg.setSubject(emailInfo.getSubject());
msg.setHeader("X-Mailer", "regmailer");
msg.setSentDate(new Date());
msg.setDataHandler(new DataHandler(emailInfo.getContent(), "text/html"));
Transport tran = (Transport) session.getTransport("smtp");
tran.connect(smtpServer,authenticator.getAccount(),authenticator.getPassword());
tran.send(msg);
} catch (Exception ex) {
logger.error("Error sending email message: "+ ex);
throw new UserException("Error sending email message: "
+ ex);
}
}
xiaoxiao1987918 2008-07-11
  • 打赏
  • 举报
回复
再请教各位一个问题,我发出邮件内容,都给显示成了(????????)了,那编码格式要怎么设置啊?
mackson 2008-07-10
  • 打赏
  • 举报
回复
tom稍微稳定一点
xiaoxiao1987918 2008-07-10
  • 打赏
  • 举报
回复
我自己的是2006年,我后来问我同事要了个几年前的邮箱,可是还是出这样的异常!郁闷啊!
lovingprince 2008-07-10
  • 打赏
  • 举报
回复
有时候要看你的163邮箱帐号知否支持smtp功能。现在126就有这种限制,在2006年还是2007年几月份开始申请的新邮箱都不能使用POP3功能,非常郁闷。

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧