软件包javax.mail和javax.mail.internet不存在
当我编译具有以下2个import语句的简单代码时:
import javax.mail.*
import javax.mail.internet.*
我收到以下消息:
package javax.mail does not exist
package javax.mail.internet does not exist
为什么会出现此错误?
这是我的代码:
import javax.mail.*;import javax.mail.internet.*;
import java.util.*;
class tester {
public static void main(String args[]) {
Properties props = new Properties();
props.put("mail.smtp.com" , "smtp.gmail.com");
Session session = Session.getDefaultInstance( props , null);
String to = "me@gmail.com";
String from = "from@gmail.com";
String subject = "Testing...";
Message msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO , new InternetAddress(to));
msg.setSubject(subject);
msg.setText("Working fine..!");
} catch(Exception exc) {
}
}
}
回答:
您需要下载JavaMail
API,并将相关的jar文件放入您的类路径中。
以上是 软件包javax.mail和javax.mail.internet不存在 的全部内容, 来源链接: utcz.com/qa/432266.html