包javax.mail和javax.mail.internet不存在 [英] package javax.mail and javax.mail.internet do not exist

查看:5007
本文介绍了包javax.mail和javax.mail.internet不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编译一个包含以下2个import语句的简单代码时:

When I compile a simple code that has the following 2 import statements:

import javax.mail。*

import javax.mail.internet。*

我收到以下消息:

包javax.mail不存在

包javax.mail.internet不存在

为什么我得到这个错误?

Why do I get this error?

这是我的代码:

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文件放在您的类路径中。

You need to download the JavaMail API, and put the relevant jar files in your classpath.

这篇关于包javax.mail和javax.mail.internet不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆