When I compile a simple code that has the following 2 import statements:
import javax.mail.*
import javax.mail.internet.*
I get the following message:
package javax.mail 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 = "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) {
}
}
}
asked Jul 7, 2011 at 6:11
saplingProsaplingPro
20.4k53 gold badges136 silver badges193 bronze badges
You need to download the JavaMail API, and put the relevant jar files in your classpath.
answered Jul 7, 2011 at 6:14
Jon SkeetJon Skeet
1.4m851 gold badges9045 silver badges9133 bronze badges
0
If using maven, just add to your 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.
answered Jan 10, 2016 at 11:04
Download javax.mail.jar
and add it to your project using the following steps:
- 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
Dave Jarvis
29.9k39 gold badges177 silver badges310 bronze badges
answered Mar 2, 2013 at 10:57
BibinBibin
2542 silver badges9 bronze badges
1
You need the javax.mail.jar
library.
Download it from the Java EE JavaMail GitHub page and add it to your IntelliJ project:
- 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
answered May 17, 2016 at 15:56
ordonezalexordonezalex
2,5751 gold badge21 silver badges33 bronze badges
0
For anyone still looking to use the aforementioned IMAP library but need to use gradle, simply add this line to your modules gradle file (not the main gradle file)
compile group: 'javax.mail', name: 'mail', version: '1.4.1'
The links to download the .jar file were dead for me, so had to go with an alternate route.
Hope this helps
answered Sep 27, 2017 at 19:01
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.
answered Jul 7, 2011 at 6:15
npintinpinti
51.5k5 gold badges73 silver badges95 bronze badges
You need the javax.mail.jar library. Download it from the https://www.oracle.com/java/technologies/javamail-releases.html and add it to your Eclipse project:
If you are using <module-info.java> then,
- Right-click on Project, go to Build Path -> Configure Build Path -> Libraries -> ModulePath -> Add External Jars.
- Browse to the javax.mail.jar file
- Click «Apply and Close».
Under module-info.java, add this:
module TestApp {
**requires mail;**
}
answered May 22, 2021 at 17:36
you have to set the classpath of your mail.jar
and activation.jar
file like that:
open the command prompt:
c:user>set classpath=%classpath%;d:jarfilesmail.jar;d:jarfilesactivation.jar;.;
and if u don’t have the both file then please download them here
Eugene Loy
12.2k8 gold badges53 silver badges79 bronze badges
answered Dec 6, 2013 at 7:59
-
Download the Java mail jars.
-
Extract the downloaded file.
-
Copy the «.jar» file and paste it into
ProjectNameWebContentWEB-INFlib
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
ProjectNameWebContentWEB-INFlib
and click OKthat’s all
answered Jul 16, 2017 at 7:48
Had the same issue. Obviously these .jars were included with Java <= v8.x out of the box, but are not anymore. Thus one has to separately download them and place them in the appropriate classpath as highlighted by several folks above. I understand that the new Java is modularized and thus potentially more light-weight (which is certainly a good thing, since the old setup was a monster). On the other hand this — as we can see — breaks lots of old build setups. Since the time to fix these isn’t chargeable to Oracle I guess this made their decision easy…
answered Jul 12, 2018 at 15:41
mmommo
3,81410 gold badges40 silver badges60 bronze badges
you need mail.jar and activation.jar to build javamail application
answered Jul 7, 2011 at 6:26
gitee.comgitee.com
4261 gold badge4 silver badges8 bronze badges
3
answered Jan 3, 2013 at 10:51
Ripon Al WasimRipon Al Wasim
36.4k42 gold badges153 silver badges173 bronze badges
I just resolved this for myself, so hope this helps. My project runs on GlassFish 4, Eclipse MARS, with JDK 1.8 and JavaEE 7.
Firstly, you can find javax.mail.jar
in the extracted glassfish
folder: 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
answered Sep 11, 2015 at 2:50
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
private void sendMail() throws MessagingException{
String host = "smtp.gmail.com";
String password = "abcde12345";
String from = "testing@gmail.com";
String toAddress = email;
String filename = Environment.getExternalStorageDirectory() + "/jam.jpg";
Properties properties = System.getProperties();
properties.put("mail.smtp.host", host);
properties.put("mail.smtps.auth", true);
properties.put("mail.smtp.starttls.enable", true);
Session session = Session.getInstance(properties, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, toAddress);
message.setSubject("Anti-Theft Attachment");
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(smsMessageString);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
try{
Transport transport = session.getTransport("smtps");
transport.connect(host, from, password);
transport.sendMessage(message, message.getAllRecipients());
System.out.println("Mail Sent Successfully");
transport.close();
} catch (SendFailedException sfe){
System.out.println(sfe);
}
};
I am developing an application which the application will automatically send out an email to user informing user the current phone status once the phone is stolen or lost. But I faced problem in importing javax.mail «The import javax.mail cannot be resolved». What should I do? Thanks…
I have been using eclipse to code and test my software on Windows. When I copy the code to Ubuntu, I cannot compile the code as it cannot find the Javax files to import. I know I need to add the classpath where the jar file is located. My question is where or what name is the jar file? Any suggestions much appreciated.
Compile statement
javac eMail.java
Java code
import javax.mail.Folder;
import javax.mail.Message;
Error
import javax.mail.Folder;
^
eMail.java:7: error: package javax.mail does not exist
for each import statement.
asked Apr 3, 2020 at 17:35
As far as I know the mail library has always been an external download. It’s currently located on github at https://github.com/javaee/javamail/releases. Download it and add it to your classpath in Eclipse.
answered Apr 3, 2020 at 17:50
rtaftrtaft
1,7253 gold badges13 silver badges24 bronze badges
1
If you developed on Windows first you have to take into account what Build Paths your project had in there. I think you could take two approach to solve this:
1-Screnshot/Write down build path and project preferences from Windows and try to replicate that on your Linux dev machine, see eclipse documentation
2-Export your Windows projects and then import them on Linux, please see this StackOVerflow question
Also I think you shouldn’t asking here for locations of jar files from your projects, If you are the developer you should know where the files needed by your projects are(Just IMHO, don’t take this as a personal attack please ;))
answered Apr 3, 2020 at 18:07