Javax.mail. package not recognised

Hi people!!!!
Please help me out as I am new to j2ee/JavaMail
I have the j2ee sdk 1.4 installed as well as j2se1.4.2/netbeans conbundle.
I would create to a simple application that sends an email. However, the compiler doesn't recognise the javax.mail.* and javax.mail.internet.* packages.
When I type j2ee -verbose at the command prompt it states that it doesn't recognise the command.
I have set my environment variables as follows:
J2EE_PATH:      C:\Sun\AppServer\
J2EE_HOME:     C:\Sun\AppServer\
JAVA_HOME:     C:\Program Files\j2sdk_nb\j2sdk1.4.2\
System Variables:
CLASSPATH:     C:\Sun\AppServer\lib\j2ee.jar
PATH:     %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\MSSQL7\BINN;C:\Program Files\j2sdk_nb\j2sdk1.4.2\bin\;C:\TOOLS\Tomcat4.1\webapps\Intranet\WEB-INF\classes\;C:\Sun\AppServer\bin\
Do perhaps know what I have not done correctly....
Thanks, any assistance will be much appreciated.
You may email your answers to me at [a href='mailto:[email protected]'][email protected][\a] if you wish
Regards
Ushanta

Hey I have added the mail.jar file to my classpath and I don't get this error any more.... Unfortunately, though I get a java.lang.NoClassDefFoundError Exception in thread 'main'
I do have a main method, here is my code:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
import java.io.*;
* @author user
public class SimpleSender {
/** Creates a new instance of SimpleSender */
public SimpleSender() {
public static void main(String[] args) {
if (args.length != 3) {
System.out.println("ERROR");
System.exit(1);
String host = args[0];
String to = args[1];
String from = args[2];
String contentType = "text/html";
Properties props = System.getProperties();
props.put("mail.smtp.host", args[0]);
try{
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setSubject("Hello");
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
String text = "<h1>testing email</h1>";
message.setContent(text, "text/html");
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
}

Similar Messages

  • Package javax.mail does not exist (Still having trouble)

    Good Morning
    I know that there are several posts regarding issues with javamail. I have viewed them for the past hour. While several of them address my issue I have been unable to locate a solution.
    Bare with me please, I am making this post very thorough. The other threads I have read are frusterating because the problems people tend to post are not clear.
    I am trying to run "msgsend" which is a provided demo of javamail-1.4 using command prompt (start - run - cmd) with the javac command.
    The output below is directly pasted from command prompt and written in bold.
    C:\download\javamail-1.4\demo>javac msgsend.java
    C:\download\javamail-1.4\demo>javac msgsend.java
    msgsend.java:44: package javax.mail does not exist
    import javax.mail.*;
    ^
    msgsend.java:45: package javax.mail.internet does not exist
    import javax.mail.internet.*;
    ^
    msgsend.java:140: cannot find symbol
    symbol : class Session
    location: class msgsend
    Session session = Session.getInstance(props, null);
    ^
    msgsend.java:140: cannot find symbol
    symbol : variable Session
    location: class msgsend
    Session session = Session.getInstance(props, null);
    ^
    msgsend.java:145: cannot find symbol
    symbol : class Message
    location: class msgsend
    Message msg = new MimeMessage(session);
    ^
    msgsend.java:145: cannot find symbol
    symbol : class MimeMessage
    location: class msgsend
    Message msg = new MimeMessage(session);
    ^
    msgsend.java:147: cannot find symbol
    symbol : class InternetAddress
    location: class msgsend
    msg.setFrom(new InternetAddress(from));
    ^
    msgsend.java:151: package Message does not exist
    msg.setRecipients(Message.RecipientType.TO,
    ^
    msgsend.java:152: cannot find symbol
    symbol : variable InternetAddress
    location: class msgsend
    InternetAddress.parse(to,
    ^
    msgsend.java:154: package Message does not exist
    msg.setRecipients(Message.RecipientType.CC,
    ^
    msgsend.java:155: cannot find symbol
    symbol : variable InternetAddress
    location: class msgsend
    InternetAddress.parse(cc,
    ^
    msgsend.java:157: package Message does not exist
    msg.setRecipients(Message.RecipientType.BCC,
    ^
    msgsend.java:158: cannot find symbol
    symbol : variable InternetAddress
    location: class msgsend
    InternetAddress.parse(bcc,
    ^
    msgsend.java:167: cannot find symbol
    symbol : class MimeBodyPart
    location: class msgsend
    MimeBodyPart mbp1 = new MimeBodyPart();
    ^
    msgsend.java:167: cannot find symbol
    symbol : class MimeBodyPart
    location: class msgsend
    MimeBodyPart mbp1 = new MimeBodyPart();
    ^
    msgsend.java:169: cannot find symbol
    symbol : class MimeBodyPart
    location: class msgsend
    MimeBodyPart mbp2 = new MimeBodyPart();
    ^
    msgsend.java:169: cannot find symbol
    symbol : class MimeBodyPart
    location: class msgsend
    MimeBodyPart mbp2 = new MimeBodyPart();
    ^
    msgsend.java:171: cannot find symbol
    symbol : class MimeMultipart
    location: class msgsend
    MimeMultipart mp = new MimeMultipart();
    ^
    msgsend.java:171: cannot find symbol
    symbol : class MimeMultipart
    location: class msgsend
    MimeMultipart mp = new MimeMultipart();
    ^
    msgsend.java:185: cannot find symbol
    symbol : variable Transport
    location: class msgsend
    Transport.send(msg);
    ^
    msgsend.java:193: cannot find symbol
    symbol : class Store
    location: class msgsend
    Store store = null;
    ^
    msgsend.java:195: cannot find symbol
    symbol : class URLName
    location: class msgsend
    URLName urln = new URLName(url);
    ^
    msgsend.java:195: cannot find symbol
    symbol : class URLName
    location: class msgsend
    URLName urln = new URLName(url);
    ^
    msgsend.java:212: cannot find symbol
    symbol : class Folder
    location: class msgsend
    Folder folder = store.getFolder(record);
    ^
    msgsend.java:218: cannot find symbol
    symbol : variable Folder
    location: class msgsend
    folder.create(Folder.HOLDS_MESSAGES);
    ^
    msgsend.java:220: cannot find symbol
    symbol : class Message
    location: class msgsend
    Message[] msgs = new Message[1];
    ^
    msgsend.java:220: cannot find symbol
    symbol : class Message
    location: class msgsend
    Message[] msgs = new Message[1];
    27 errors
    Here are the methods I have tried...
    1. Make sure you have most current version of Java
    2. Reinstall Java
    3. Attempt to compile in an IDE (Attempted in Eclipse 3.2)
    4. Set class path
    Some sources suggest "CLASSPATH" some suggest "CLASS PATH" as the variable name. I have tried both.
    Below is what the classpath looks like in bold.
    Variable Name: CLASS PATH
    Variable value: c:\download\javamail-1.4\mail.jar;C:\download\jaf-1.1\activation.jar;.
    I have double checked all folder names and copy pasted all entries to eliminate typos. Javamail-1.4 and jaf-1.1 are both located in c:\download which is the same location Class Path points to.
    Thank you very much for your input and effort. I can imagine how frusterating it is responding to 20million javamail posts :) (that may be a bit of an overstatement!)
    Thank you again!
    Irbi
    Message was edited by:
    irbi
    Message was edited by:
    irbi

    Yes - I have read that part of the README and did exactly as it has said in a previous attempt. I should have mentioned that here I'm sorry :)
    I moved the .jar files into the download folder and set the classpath exactly as the readme shows.
    When I do that the msgsend.java compiles correctly but it still does not run.
    Below is what happens.
    C:\download\javamail-1.4\demo>set CLASSPATH=%CLASSPATH%;c:\download\javamail-1.4
    \mail.jar;%CLASSPATH%;c:\download\jaf-1.1\activation.jar.
    C:\download\javamail-1.4\demo>javac msgsend.java
    C:\download\javamail-1.4\demo>java msgsend.java
    Exception in thread "main" java.lang.NoClassDefFoundError: msgsend/java
    C:\download\javamail-1.4\demo>
    I have tried fixing this error as well via forums and FAQs but it seems to be the most generic error.
    One suggestion was to clear your classpath. I tried this with a test hello world program which was giving the same error - "NoClassDefFoundError". By clearing the classpath I was able to get the hello world program to run without this error. But I can't just clear the classpath in this instance because it needs to point to mail.jar and activation.jar for the program to compile.
    Thanks again for all of your efforts. You are more appreciated than you know.

  • Import javax.mail package does not exists

    Hi,
    when i tried to compile the source code for email using jdk1.3.1, it compiled fine. but when i tried to compile using jdk1.4.., it had the following errors such as
    import javax.mail package does not exists,
    import javax.mail.internet package does not exists
    package javax.activation does not exist
    Is it because of the jdk version problem???
    Pls help me

    I have the same problem with javax.ejb
    Now i've downloaded and installed the j2ee and set my classpath to the j2ee.jar. I've had to make a new path cause i'm running XP.
    This doesn't work.
    to compile it in Jcreator or JBuilder I can make it work by adding this package (j2ee.jar) in the project settings - required libraries.
    But I have to do this for every project again and again.
    I can make it work but i thougt the classpath would be enough ??
    Bassegio

  • Package javax.mail does not exist. Please Help !

    Hi all,
    I am new to Java and I downloaded some sample application and when I try to compile it, I get an error:
    "package javax.mail does not exist".
    I've looked through forums and I know something is wrong with CLASSPATHS and that I also have to download the java mail package, but I dont know how to exactly fix this problem. I would appreciate very much if someone could help me, maybe by telling me the steps I need to take.
    Thanks.

    Hey Rom,
    Thanks for reply.
    The sample application is an authentication module:
    http://java.sun.com/j2se/1.4.2/docs/guide/security/jaas/tutorials/GeneralAcnOnly.html
    But I think this doesnt really matter, as the error I get is because I have manually added the : import java.mail.*; statement. (Maybe I had to mention it in the previous post). Because I want to add some mail client inside.
    I am compiling it using the command: javac, from the commandline menu.

  • Error: Javax.mail does not exist, please help

    I have copies mail.jar and activation.jar in the classpath directory as instructed, then try to compile but got the below error: package javax.mail does not exist
    please help.
    G:\CRD>javac SendMailBean.java
    SendMailBean.java:22: package javax.mail does not exist
    import javax.mail.*; //JavaMail packages
    ^
    SendMailBean.java:23: package javax.mail.internet does not exist
    import javax.mail.internet.*; //JavaMail Internet packages
    ^
    SendMailBean.java:43: cannot resolve symbol
    symbol : class Session
    location: class SendMailBean
    Session l_session = Session.getDefaultInstance(l_props, null);
    ^
    SendMailBean.java:43: cannot resolve symbol
    symbol : variable Session
    location: class SendMailBean
    Session l_session = Session.getDefaultInstance(l_props, null);
    ^
    SendMailBean.java:48: cannot resolve symbol
    symbol : class MimeMessage
    location: class SendMailBean
    MimeMessage l_msg = new MimeMessage(l_session); // Create a New message
    ^
    SendMailBean.java:48: cannot resolve symbol
    symbol : class MimeMessage
    location: class SendMailBean
    MimeMessage l_msg = new MimeMessage(l_session); // Create a New message
    ^
    SendMailBean.java:50: cannot resolve symbol
    symbol : class InternetAddress
    location: class SendMailBean
    l_msg.setFrom(new InternetAddress(p_from)); // Set the From address
    ^
    SendMailBean.java:53: package Message does not exist
    l_msg.setRecipients(Message.RecipientType.TO,
    ^
    SendMailBean.java:54: cannot resolve symbol
    symbol : variable InternetAddress
    location: class SendMailBean
    InternetAddress.parse(p_to, false));
    ^
    SendMailBean.java:57: package Message does not exist
    l_msg.setRecipients(Message.RecipientType.CC,
    ^
    SendMailBean.java:58: cannot resolve symbol
    symbol : variable InternetAddress
    location: class SendMailBean
    InternetAddress.parse(p_cc, false));
    ^
    SendMailBean.java:62: package Message does not exist
    l_msg.setRecipients(Message.RecipientType.BCC,
    ^
    SendMailBean.java:63: cannot resolve symbol
    symbol : variable InternetAddress
    location: class SendMailBean
    InternetAddress.parse(p_bcc, false));
    ^
    SendMailBean.java:68: cannot resolve symbol
    symbol : class MimeBodyPart
    location: class SendMailBean
    MimeBodyPart l_mbp = new MimeBodyPart();
    ^
    SendMailBean.java:68: cannot resolve symbol
    symbol : class MimeBodyPart
    location: class SendMailBean
    MimeBodyPart l_mbp = new MimeBodyPart();
    ^
    SendMailBean.java:72: cannot resolve symbol
    symbol : class Multipart
    location: class SendMailBean
    Multipart l_mp = new MimeMultipart();
    ^
    SendMailBean.java:72: cannot resolve symbol
    symbol : class MimeMultipart
    location: class SendMailBean
    Multipart l_mp = new MimeMultipart();
    ^
    SendMailBean.java:83: cannot resolve symbol
    symbol : variable Transport
    location: class SendMailBean
    Transport.send(l_msg);
    ^
    SendMailBean.java:98: cannot resolve symbol
    symbol : class MessagingException
    location: class SendMailBean
    } catch (MessagingException mex) { // Trap the MessagingException Error
    ^
    19 errors

    Another person who doesn't understand how to set CLASSPATH.
    Move those JARs into the same directory as your SendMailBean.java and do it like this:
    javac -classpath .;mail.jar;activation.jar -d . *.java
    java -classpath .;mail.jar;activation.jar SendMailBeanRead how to set CLASSPATH properly:
    http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/classpath.html

  • Error using javax.mail package

    Hi,
    I have included the package javax.mail.* in my code.I have downloaded
    jaf 1.0.2 and javamail 1.1.3 from the Sun Microsystems website.
    When i try to compile my code i get the error message:
    com/voxspectrum/ccvox/EmailServer.java:55: cannot resolve symbol
    symbol : class MimeMessage
    location: class com.voxspectrum.ccvox.EmailServer
    javax.mail.Message msg = new MimeMessage(session);
    I am using JDK ver 1.3.1_02. What should i set my path and classpath as, if i am using javax.mail package?
    Please could you help me out with this problem!

    Hi Nisha
    You need to include the path to the mail.jar and activation.jar files in your classpath.
    How you do it depends on the OS you are running on
    in Windows 95 /98 the easiest way is to edit the autoexec.bat file and add the settings to your already existing classpath statement i.e.
    set CLASSPATH=%CLASSPATH%;C:\richard\javamail-1.3\mail.jar C:\richard\jaf-1.0.2\activation.jar
    (excuse the word wrapping) then reboot
    on Linux / Solaris edit the .profile file for your user and set the CLASSPATH variable to
    CLASSPATH=$CLASSPATH:<pathtofile>/mail.jar:<pathtofile>/activation.jar
    export CLASSPATH
    and that should do it
    Hope this helps

  • Javax.mail.MessagingException: Not Connected

    Hi All,
    I am trying to read the message from pop.gmail.com using JavaMail API.I ma using POP3 protocol for it.
    But I got the following Exception
    javax.mail.MessagingException: Not Connected
    at com.sun.mail.pop3.POP3Store.checkConnected(POP3Store.java:279)
         at com.sun.mail.pop3.POP3Store.getFolder(POP3Store.java:261)
         at MailReceipt.connect(MailReceipt.java:97)
         at MailReceipt.mailRecieve(MailReceipt.java:62)
         at MailReceipt.main(MailReceipt.java:53)
    I got This Error at the line
    folder = store.getFolder("INBOX");
    in my program.
    Please Help me ion this regards.Thanks in Adnavce..
    Thanx & Regards
    Sandeep Verma

    Well, I've never used this API but it seems 100% clear what's wrong. And 5 seconds with Google has revealed that there's a method on that class which looks like it will address the issue.
    If you can't even read basic error messages, you should seriously question whether you should be programming.

  • Javax.mail does not exist

    I would like to thank warnerja for your advise about the classpath.
    Thanks for the classpath information regarding the .jar files. Now when I start tomcat cat it runs appropriately. However I am still having a problem when i try to compile the message send demo. The message I get is javax.mail does not exist,(import javax.mail.) when I downloade the mail api I placed on the root of my D drive and i placed the mail and activation jar files in my lib folded of my Jakarta-3.2.1 lib folder. I graduated Chubb Institute back in october and am currently still looking for work so my memory but be a little fuzzy as to whether or not this is correct. Your help is greatly appreciated.

    If you are just compiling the classes then you should check that the mail.jar file is in your compiler classpath. How you check and set it depends on how you are compiling it and on what system etc.

  • Getting free download of javax.mail package

    where can i get free download for javax.mail package
    Which can be used for retrieving mails/attachments

    http://java.sun.com/products/javamail/index.html

  • I want javax.mail package

    Hi all,
    Please tell me the location where I need to download the javax.mail package.
    Thanks
    Anand

    http://java.sun.com/products/javamail/index.html

  • Reader 10.1.7 Windows xp,  can't access at all just get message the patch package not recognised

    Reader 10.1.7 with windows xp,  can't access at all,  or remove ,  just get message that patch package not recognised. Or else Runtime error  Help please

    Uninstall the corrupted Reader installation using http://labs.adobe.com/downloads/acrobatcleaner.html
    then reinstall the latest version from http://get.adobe.com/reader/enterprise/

  • Package javax.mail.* not found

    Hello.
    I've got a problem with a program in which I wanted to use the JavaMail-API. I've added the path of the needed jar-files into the CLASSPATH. But when I compile my application I get the error that the package java.mail.* was not found.
    I've also tried it with the JBuilder5 and then I got the followed error message:
    Error #: 302 : No access on the class javax.mail.Session; class javax.mail.Session was not found in a stable package
    What did I do wrong? Please help me.

    The problem is evident, the class you want to use is not in class path. There is no dilemma over that.
    How can you check that the class is in classpath.
    you can use javap command
    If you are using WIN NT /200o you can use the command
    javap with fully qualified name of the class e.g.
    to find if the class String is in classpath
    ==> javap java.lang.String
    This will print all the methods of the class on the DOSpromt. Similarly you can check
    javap javax.mail.Session
    if it doesnot find the class, the class is definitely not in classpath. You can set the class path as: -
    set classpath = %classpath%;"path of mail.jar"
    if mail.jar is located in say c:\jdk1.3\lib\mail.jar
    set the classpath as :-
    set classpath = %classpath%;C:\jdk1.3\lib\mail.jar;C:\jdk1.3\lib\activation.jar
    Now check with javap it is working now and now you can compile you code.
    Hope this helps

  • Javax.mail.*; not being seen by portal in EP 6

    Hello All,
    It seems that when I deploy the following code:
    package com.giggity;
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.AddressException;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;
    import com.sapportals.portal.prt.component.AbstractPortalComponent;
    import com.sapportals.portal.prt.component.IPortalComponentRequest;
    import com.sapportals.portal.prt.component.IPortalComponentResponse;
    public class Mailer extends AbstractPortalComponent
      public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
      Properties p = System.getProperties();
      p.put("mail.host", "stmail");
      try{
      MimeMessage message =
    new MimeMessage(Session.getInstance(p, null));
    message.setFrom(new InternetAddress("[email protected]"));               message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]"));
    message.setSubject("No work");
    message.setText("Does not work");
    Transport.send(message);
    catch(Exception e)
    I get a javax/mail/Address ClassNotFoundException.  In
    the IDE (Eclipse with PDK plugin, not using NW04), it
    compiles and builds just fine.  What is the problem?
    Thanks.
    -Greg

    Successful compilation or building in the eclipse/NWDS does not mean that it can be successfully deployed on the portal. If the Java build path has all the required jars, any project compiles and builts fine but that build path is not transported to the portal( see inside any par file, there won't be any .classpath and .project files. They are local only files).
    ========
       Add all your third party jar files to the component in this path( ..\dist\PORTAL-INF\lib). There is no need to add mail.jar as it's already available in sap j2ee engine. So add these lines to the portalapp.xml. (as told by jagdeep)
    <application-config>
    <property name="PrivateSharingReference" value="SAPJ2EE::library:mail"/>
    </application-config>
    Regs,
    Bobby

  • Javax.mail emails not sent

    Hi,
    We are sending emails through the javax.mail class in our application,
    basically
    it works fine, however I was wondering how I could do one of the two:
    1. validate an email address to be correct (existing, not using the java
    classes for rfc validation, but actualy pinging it).
    2. receive a notification about the undeliverable email when it happens (if
    it goes back to weblogic at all, I think I saw a message on the console).
    any help is will be appreciated,
    thanks.
    Asher Bitton

    Stevie, asap...
    Using Disk Utility in Mac OS X 10.4.3 or later to verify or repair disks...
    http://docs.info.apple.com/article.html?artnum=302672
    About Disk Utility's Repair Disk Permissions feature...
    http://docs.info.apple.com/article.html?artnum=25751

  • Javax.smartcardio package not found in Java source file

    I downloaded the latest JDK from developer.apple.com, but now I cannot find the javax.smartcardio package in the source package (src.jar) that came with it. I unpacked the JAR file, but simply can't find the stated package. Can you help me out?

    I can confirm the issue here (Mountain Lion, 10.8.5). A very simple program (attached below) that just enumerates terminals and checks if a card is present will crash:
    If Apple JDK6 is used in 64-bit mode (without supplying the -d32 argument)
    If Oracle JDK7 is used (can not switch to 64-bit, uses)
    It will work if:
    If Apple JDK6 is forced into 32-bit mode using -d32
    If Oracle JDK7 version of libj2pcsc.dylib is replaced with a patched version
    javax.smartcardio on Mac OS X is in a truly sad state. :-(
    Can anyone suggest alternatives for Smartcard communication on Mac OS X fat clients?
    package com.example.smartcardio;
    import javax.smartcardio.CardTerminal;
    import javax.smartcardio.CardTerminals;
    import javax.smartcardio.TerminalFactory;
    public class TestWaitForChanges {
              public static void main(String[] args) throws Exception {
                        CardTerminals terminals = TerminalFactory.getDefault().terminals();
                        while (true) {
                                  for (CardTerminal terminal : terminals.list()) {
                                            System.out.println("Checking terminal: " + terminal.getName());
                                            System.out.println("Card present: " + (terminal.isCardPresent() ? "YES" : "NO"));
                                  System.out.println("Waiting for changes...");
                                  terminals.waitForChange();

Maybe you are looking for