专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Java Exception

javax.mail.AuthenticationFailedException异常

发布时间:2010-06-05 12:27:31 文章来源:www.iduyao.cn 采编人员:星星草

我在servlet中写的邮件发送,老是提示javax.mail.AuthenticationFailedException错误,查了半天也没查出来是什么原因,请各位高手帮帮忙,源码如下:
String smtpServer = request.getParameter( "txtserver ");
  String emailTo = request.getParameter( "txtto ");
  String fromemail = request.getParameter( "txtfrom ");
  String subject = request.getParameter( "txtsubject ");
  String body = request.getParameter( "txtmessage ");

  try
  {
  Properties props = new Properties() ;
  props.put( "mail.transport.protocol ", "smtp ");
  props.put( "mail.smtp.auth ", "true ");
  props.put( "mail.smtp.host ",smtpServer);
  props.put( "mail.smtp.port ", "25 ");
  Session mailsession = Session.getInstance(props);
  Message msg = new MimeMessage(mailsession);

  msg.setFrom(new InternetAddress(fromemail));
  msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(emailTo));
  msg.setSentDate(new Date());
  msg.setSubject(subject);
  msg.setText(body);
  msg.saveChanges() ;
// Transport transport;
// transport = mailsession.getTransport( "smtp ");
// transport.connect((String)props.get( "smtp.163.com "), "caojunkeke ", "06240624 ");
  Transport.send(msg);
  msg.writeTo(System.out );
  out.print( "邮件已成功发送到 ");
  }
  catch(Exception e)
  {
  System.out.println(e);
  }


------解决方法--------------------------------------------------------
需要验证,当然不行了

final String username = "username ";
  final String password = "password ";
 
  //使用验证
  Session session = Session.getDefaultInstance(props,     

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: