包 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
package javax.mail and javax.mail.internet do not exist
提问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
回答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.jar
and add it to your project using the following steps:
javax.mail.jar
使用以下步骤下载并将其添加到您的项目中:
- Extract the mail.jar file
- Right click the project node (JavaMail), click Properties to change properties of the project
- Now go to Libraries Tab
- Click on Add JAR/Folder Button. A window opens up.
- Browse to the location where you have unzipped your Mail.jar
- Press ok
- Compile your program to check whether the JAR files have been successfully included
- 解压 mail.jar 文件
- 右键单击项目节点(JavaMail),单击属性更改项目的属性
- 现在转到库选项卡
- 单击添加 JAR/文件夹按钮。一个窗口打开。
- 浏览到您解压 Mail.jar 的位置
- 按确定
- 编译您的程序以检查是否已成功包含 JAR 文件
回答by Abhishek Singh
you have to set the classpath of your mail.jar
and activation.jar
file like that:
你必须像这样设置你mail.jar
和activation.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 4、Eclipse MARS、JDK 1.8和JavaEE 7 上运行。
Firstly, you can find javax.mail.jar
in the extracted glassfish
folder: 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.jar
library.
Download it from the Java EE JavaMail GitHub pageand add it to your IntelliJ project:
你需要javax.mail.jar
图书馆。从Java EE JavaMail GitHub 页面下载它并将其添加到您的 IntelliJ 项目中:
- Download
javax.mail.jar
- Navigate to
File > Project Structure...
- Go to the Libraries tab
- Click on the
+
button (Add New Project Library) - Browse to the
javax.mail.jar
file - Click OK to apply the changes
- 下载
javax.mail.jar
- 导航
File > Project Structure...
- 转到库选项卡
- 单击
+
按钮(添加新项目库) - 浏览到
javax.mail.jar
文件 - 单击“确定”以应用更改
回答by Saikat Kundu
- Downloadthe Java mail jars.
- Extract the downloaded file.
- Copy the ".jar" file and paste it into
ProjectName\WebContent\WEB-INF\lib
folder - Right click on the Project and go to Properties
- Select Java Build Path and then select Libraries
- Add JARs...
Select the .jar file from
ProjectName\WebContent\WEB-INF\lib
and click OKthat's all
- 下载Java 邮件 jar。
- 提取下载的文件。
- 复制“.jar”文件并将其粘贴到
ProjectName\WebContent\WEB-INF\lib
文件夹中 - 右键单击项目并转到属性
- 选择 Java 构建路径,然后选择库
- 添加 JAR...
从中选择 .jar 文件
ProjectName\WebContent\WEB-INF\lib
并单击“确定”就这样