Forum Stats

  • 3,769,701 Users
  • 2,253,011 Discussions
  • 7,875,155 Comments

Discussions

Package Javax.Mail does not exist

843834
843834 Member Posts: 49,972
edited Jul 21, 2008 11:40AM in JavaMail
I'm working on a program that emails information after getting it from a database. I used some of the demo programs included with the JavaMail API and they all ran fine. I then made my own program to use the thing I learned and test emailing the kind of data I would get from my database. All these programs compile and run fine. When I added the email capability to my database program and compiled it I got:
C:\Documents and Settings\DCosta\Netbeans\6.0\workspace\DPSLib\src\com\agois\dps\service\DefaultEmailPDFService.java:19: package javax.mail does not exist
import javax.mail.Authenticator;
C:\Documents and Settings\DCosta\Netbeans\6.0\workspace\DPSLib\src\com\agois\dps\service\DefaultEmailPDFService.java:20: package javax.mail does not exist
import javax.mail.Message;
C:\Documents and Settings\DCosta\Netbeans\6.0\workspace\DPSLib\src\com\agois\dps\service\DefaultEmailPDFService.java:21: package javax.mail does not exist
import javax.mail.Session;
C:\Documents and Settings\DCosta\Netbeans\6.0\workspace\DPSLib\src\com\agois\dps\service\DefaultEmailPDFService.java:22: package javax.mail does not exist
import javax.mail.Transport;
C:\Documents and Settings\DCosta\Netbeans\6.0\workspace\DPSLib\src\com\agois\dps\service\DefaultEmailPDFService.java:23: package javax.mail.internet does not exist
import javax.mail.internet.InternetAddress;
C:\Documents and Settings\DCosta\Netbeans\6.0\workspace\DPSLib\src\com\agois\dps\service\DefaultEmailPDFService.java:24: package javax.mail.internet does not exist
import javax.mail.internet.MimeBodyPart;
C:\Documents and Settings\DCosta\Netbeans\6.0\workspace\DPSLib\src\com\agois\dps\service\DefaultEmailPDFService.java:25: package javax.mail.internet does not exist
import javax.mail.internet.MimeMessage;
C:\Documents and Settings\DCosta\Netbeans\6.0\workspace\DPSLib\src\com\agois\dps\service\DefaultEmailPDFService.java:26: package javax.mail.internet does not exist
import javax.mail.internet.MimeMultipart;
C:\Documents and Settings\DCosta\Netbeans\6.0\workspace\DPSLib\src\com\agois\dps\util\SMTPAuthenticator.java:8: package javax.mail does not exist
import javax.mail.Authenticator;
C:\Documents and Settings\DCosta\Netbeans\6.0\workspace\DPSLib\src\com\agois\dps\util\SMTPAuthenticator.java:9: package javax.mail does not exist
import javax.mail.PasswordAuthentication;
I wrote and ran all these programs in NetBeans and can not understand why one program works fine when it comes to the imports and another does not. Anyone who helps, thanks in advance
-Doug

Edited by: DougCosta on Jul 17, 2008 11:05 AM

Comments

  • Did you add mail.jar as a library for your new project?
  • 843834
    843834 Member Posts: 49,972
    Of course, I tried removing it and readding it. I tried deleting the library and recreating it. I redownloaded the .jar file and added them again. Each time the application does not run.
  • Either you're doing something wrong (which is impossible to tell from here),
    or you've discovered a bug in NetBeans. Either way, having a very detailed
    list of the steps required to reproduce the problem would be helpful.
  • 843834
    843834 Member Posts: 49,972
    edited Jul 17, 2008 3:19PM
    How detailed? Do you want my source code? Unfortunately I can not give all of it, but ill post the relevant part.

    (imports omitted)
    import java.util.Collection;
    import java.util.Date;
    import java.util.HashMap;
    import java.util.Hashtable;
    import java.util.Iterator;
    import java.util.Properties;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.mail.Authenticator;
    import javax.mail.Message;
    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;

    public class DefaultEmailPDFService extends DefaultPDFGenerator implements ServiceInterface{
    (constructor omitted)

    public PrintServiceResult process(PrintServiceRequest request, Collection<CopyRoot> rootCollection) {
    (code omitted - assume all relevant variable are declared and set)
    //Set email properties
    Properties props = System.getProperties();
    props.setProperty("mail.smtp.host", SMTPServer);
    props.setProperty("mail.smtp.port",String.valueOf(SMTPPort));

    if(SSL){
    props.setProperty( "mail.smtp.socketFactory.class",
    "javax.net.ssl.SSLSocketFactory");
    props.setProperty( "mail.smtp.socketFactory.fallback", String.valueOf(fallback));
    props.setProperty( "mail.smtp.socketFactory.port", String.valueOf(SMTPPort));
    }
    Session session;
    if(username!=null)
    {
    props.setProperty("mail.smtp.auth",String.valueOf(Boolean.TRUE));
    Authenticator auth = new SMTPAuthenticator(username,password);
    session = Session.getInstance(props, auth);
    }
    else
    {
    session = Session.getInstance(props, null);
    }

    Message msg = new MimeMessage(session);
    if(fromAddress!=null) msg.setFrom(new InternetAddress(fromAddress));
    else msg.setFrom(new InternetAddress(defaultReplyAddress));
    if(replyAddress!=null) msg.setReplyTo(InternetAddress.parse(replyAddress,false));
    msg.setRecipients(Message.RecipientType.TO,
    InternetAddress.parse(emailAddress, false));
    MimeBodyPart mbp1 = new MimeBodyPart();
    if(emailText!=null)mbp1.setText(emailText);
    else mbp1.setText(text);
    MimeBodyPart mbp2 = new MimeBodyPart();
    mbp2.attachFile(fileLoc+"/"+baseFileName+".pdf");
    MimeMultipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);
    if(disclaimer!=null)
    {
    MimeBodyPart mbp3 = new MimeBodyPart();
    mbp3.setText(disclaimer);
    mp.addBodyPart(mbp3);
    }

    msg.setContent(mp);
    msg.setSentDate(new Date());
    Transport.send(msg);
    (code omitted)
    }

    The reason I highly doubt that it is my source code is that I can run a modified version(with everything hard coded) of msgsend and it works fine. What other things would you like me to post to help with debugging my problem

    Edited by: DougCosta on Jul 17, 2008 12:19 PM
  • 843834
    843834 Member Posts: 49,972
    I was able to overcome my problem by adding the .jar files to my JDK's jre folders ext folder. I have absolutely no idea why this fixes my problem (because I had a program that worked before this change) but it seems to be working. Thanks for trying to help solve my problem and if you could explain why this makes any difference thanks again.
  • Putting it in the ext directory makes it available to everything using that
    copy of the JRE. Normally, using NetBeans, you would add the jar file to the
    project using one of the project configuration dialogs. If you did that and it
    didn't work, I can't explain why.
  • 843834
    843834 Member Posts: 49,972
    [http://sourceforge.net/projects/jackmailclient]
This discussion has been closed.