当我编译具有以下2个import语句的简单代码时:
import javax.mail.*import javax.mail.internet.*
我收到以下消息:
package javax.mail does not existpackage 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文件放入您的类路径中。

关于java - 软件包javax.mail和javax.mail.internet不存在,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6606529/

10-10 02:38