日期:2014-05-19  浏览次数:20678 次

javamail 问题。帮帮我吧
Properties props = new Properties();
props.put("mail.smtp.host", host);//指定SMTP服务器
props.put("mail.smtp.auth", "true");//指定是否需要SMTP验证
try
{
Session mailSession = Session.getDefaultInstance(props);
 
mailSession.setDebug(true);//是否在控制台显示debug信息
 
Message message=new MimeMessage(mailSession);
message.setFrom(new InternetAddress("yangchongjuvip@sina.com"));//发件人
message.addRecipient(Message.RecipientType.TO,new InternetAddress("yangchongju@126.com"));//收件人
 
message.setSubject("ssss");//邮件主题
message.setText("helloworld");//邮件内容
message.saveChanges();
 
Transport transport = mailSession.getTransport("smtp");
transport.connect("smtp.sina.com", "yangchongjuvip", "123456789");
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}catch(Exception e)
{
e.printStackTrace();



错误信息————————————————————————————
DEBUG: setDebug: JavaMail version 1.4eajavax.mail.NoSuchProviderException: smtp
at javax.mail.Session.getService(Session.java:768)
at javax.mail.Session.getTransport(Session.java:708)
at javax.mail.Session.getTransport(Session.java:651)
at javax.mail.Session.getTransport(Session.java:631)
at send.send(send.java:39)
at send.main(send.java:59)

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4ea]
java.lang.ClassNotFoundException: com/sun/mail/smtp/SMTPTransport
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at javax.mail.Session.getService(Session.java:764)
at javax.mail.Session.getTransport(Session.java:708)
at javax.mail.Session.getTransport(Session.java:651)
at javax.mail.Session.getTransport(Session.java:631)
at send.send(send.java:39)
at send.main(send.java:59)

}

------解决方案--------------------
需要的包都导入了吗?放到tomcat的lib下了吗
------解决方案--------------------
java.lang.ClassNotFoundException: com/sun/mail/smtp/SMTPTransport 
可能是mail.jar没有放到web应用的lib目录,我猜的。