Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 = "[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) {        }  } } 
like image 985
saplingPro Avatar asked Jul 07 '11 06:07

saplingPro


People also ask

Which packages contain the core classes of JavaMail API?

activation packages contains the core classes of JavaMail API.


2 Answers

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

like image 53
Jon Skeet Avatar answered Sep 23 '22 03:09

Jon Skeet


Download javax.mail.jar and add it to your project using the following steps:

  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
like image 23
Bibin Avatar answered Sep 23 '22 03:09

Bibin