包 javax.mail 和 javax.mail.internet 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6606529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 08:09:26  来源:igfitidea点击:

package javax.mail and javax.mail.internet do not exist

javaemailjavax.mail

提问by saplingPro

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

当我编译具有以下 2 个导入语句的简单代码时:

import javax.mail.*

import javax.mail.*

import javax.mail.internet.*

import javax.mail.internet.*

I get the following message:

我收到以下消息:

package javax.mail does not exist

package javax.mail does not exist

package javax.mail.internet does not exist

package javax.mail.internet does not exist

Why do I get this error?

为什么我会收到这个错误?

Here is the code I have:

这是我的代码:

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 = "[email protected]";
   String from = "[email protected]";
   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) {
       }
 }
}

采纳答案by Jon Skeet

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

您需要下载JavaMail API,并将相关的 jar 文件放在您的类路径中。

回答by npinti

It might be that you do not have the necessary .jar files that give you access to the Java Mail API. These can be downloaded from here.

可能是因为您没有允许访问 Java Mail API 的必要 .jar 文件。这些可以从这里下载。

回答by gitee.com

you need mail.jar and activation.jar to build javamail application

您需要 mail.jar 和 activation.jar 来构建 javamail 应用程序

回答by Ripon Al Wasim

Download "javamail1_4_5.zip" file from http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-eeplat-419426.html#javamail-1.4.5-oth-JPR

http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-eeplat-419426.html#javamail-1.4.5-oth-JPR下载“javamail1_4_5.zip”文件

Extract zip file and put the relevant jar file ("mail.jar") in the classpath

解压 zip 文件并将相关的 jar 文件(“mail.jar”)放在类路径中

回答by Bibin

Downloadjavax.mail.jarand add it to your project using the following steps:

javax.mail.jar使用以下步骤下载并将其添加到您的项目中:

  1. Extract the mail.jar file
  2. Right click the project node (JavaMail), click Properties to change properties of the project
  3. Now go to Libraries Tab
  4. Click on Add JAR/Folder Button. A window opens up.
  5. Browse to the location where you have unzipped your Mail.jar
  6. Press ok
  7. Compile your program to check whether the JAR files have been successfully included
  1. 解压 mail.jar 文件
  2. 右键单击项目节点(JavaMail),单击属性更改项目的属性
  3. 现在转到库选项卡
  4. 单击添加 JAR/文件夹按钮。一个窗口打开。
  5. 浏览到您解压 Mail.jar 的位置
  6. 按确定
  7. 编译您的程序以检查是否已成功包含 JAR 文件

回答by Abhishek Singh

you have to set the classpath of your mail.jarand activation.jarfile like that:

你必须像这样设置你mail.jaractivation.jar文件的类路径:

open the command prompt:

打开命令提示符:

c:\user>set classpath=%classpath%;d:\jarfiles\mail.jar;d:\jarfiles\activation.jar;.;

and if u don't have the both file then please download them here

如果您没有这两个文件,请在此处下载

回答by Shagun P.

I just resolved this for myself, so hope this helps. My project runs on GlassFish 4, Eclipse MARS, with JDK 1.8and JavaEE 7.

我只是为自己解决了这个问题,所以希望这会有所帮助。我的项目在GlassFish 4Eclipse MARSJDK 1.8JavaEE 7 上运行

Firstly, you can find javax.mail.jarin the extracted glassfishfolder: glassfish4->glassfish->modules

首先,您可以javax.mail.jar在提取的glassfish文件夹中找到:glassfish4->glassfish->modules

Next, in Eclipse, Right Click on your project in the explorer and navigate the following: Properties->Java Build Path->Libraries->Add External JARs->Go to the aforementioned folder to add javax.mail.jar

接下来,在Eclipse 中,在资源管理器中右键单击您的项目并导航以下内容:Properties->Java Build Path->Libraries->Add External JARs->转到上述文件夹以添加javax.mail.jar

回答by ma31

If using maven, just add to your pom.xml:

如果使用 maven,只需添加到您的 pom.xml 中:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.5.0-b01</version>
</dependency>

Of course, you need to check the current version.

当然,您需要检查当前版本

回答by ordonezalex

You need the javax.mail.jarlibrary. Download it from the Java EE JavaMail GitHub pageand add it to your IntelliJ project:

你需要javax.mail.jar图书馆。从Java EE JavaMail GitHub 页面下载它并将其添加到您的 IntelliJ 项目中:

  1. Download javax.mail.jar
  2. Navigate to File > Project Structure...
  3. Go to the Libraries tab
  4. Click on the +button (Add New Project Library)
  5. Browse to the javax.mail.jarfile
  6. Click OK to apply the changes
  1. 下载 javax.mail.jar
  2. 导航 File > Project Structure...
  3. 转到库选项卡
  4. 单击+按钮(添加新项目库)
  5. 浏览到javax.mail.jar文件
  6. 单击“确定”以应用更改

回答by Saikat Kundu

  1. Downloadthe Java mail jars.
  2. Extract the downloaded file.
  3. Copy the ".jar" file and paste it into ProjectName\WebContent\WEB-INF\libfolder
  4. Right click on the Project and go to Properties
  5. Select Java Build Path and then select Libraries
  6. Add JARs...
  7. Select the .jar file from ProjectName\WebContent\WEB-INF\liband click OK

    that's all

  1. 下载Java 邮件 jar。
  2. 提取下载的文件。
  3. 复制“.jar”文件并将其粘贴到ProjectName\WebContent\WEB-INF\lib文件夹中
  4. 右键单击项目并转到属性
  5. 选择 Java 构建路径,然后选择库
  6. 添加 JAR...
  7. 从中选择 .jar 文件ProjectName\WebContent\WEB-INF\lib并单击“确定”

    就这样