好长时间没有上论坛了,今天逛了一下。又有很多会员了。祝中国编程论坛越来越好。
言归正转。小弟,我在做JAVAMail发送邮件时,出现了一个运行错误。请大家帮忙解决一下。代码如下:
import javax.mail.Transport;
import javax.mail.Message;
import javax.mail.Address;
import javax.mail.Message.*;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.InternetAddress;
import java.util.*;
public class MailDemo{
public MailDemo()throws Exception{}
public static void main(String[] args)throws Exception{
String from="xxxxxxx@163.com";
String to="xxxxxxx@163.com";
String host="163.com";
String username = "xuchengli375";
String password = "06338714552";
Properties props=new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth", "true");
Session session=Session.getDefaultInstance(props,null);
MimeMessage message=new MimeMessage(session);
Address faddress=new InternetAddress(from);
Address taddress=new InternetAddress(to);
message.setFrom(faddress);
message.addRecipient(Message.RecipientType.TO,taddress);
message.setSubject("JavaMail");
message.setText("Welcome to JavaMail,this is a test!");
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
}
出现的错误为:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Address
这是为什么?
[此贴子已经被作者于2007-10-2 15:45:07编辑过]
----------------解决方案--------------------------------------------------------