English 中文(简体)
Javax.mail.* 不存在一揽子计划——为什么?
原标题:Javax.mail.* Package does not exist - Why?

Im using a class called emailer to send an email from a java application,
I am using netbeans 6.9.1 and I am using J2SE, I downloaded the javamail api and added the jar to the classpath and also put it in the src for netbeans.

Netbeans正在投掷一个错误,说。 包装单javax.mail没有,I dont知道为什么? 我感到,我做了一切正确的事情,这里就是该守则。

import java.util.*;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.mail.*;
import javax.mail.internet.*;

/**
* Simple demonstration of using the javax.mail API.
*
* Run from the command line. Please edit the implementation
* to use correct email addresses and host name.
*/
public final class Emailer {

  public static void main( String... aArguments ){
    Emailer emailer = new Emailer();
        try {

            emailer.sendEmail("fromblah@blah.com", "toblah@blah.com", "Testing 1-2-3", "blah blah blah");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Emailer.class.getName()).log(Level.SEVERE, null, ex);
        }
   }


  public void sendEmail(String aFromEmailAddr, String aToEmailAddr,
    String aSubject, String aBody) throws ClassNotFoundException
  {
      Class.forName("javax.mail");

    Session session = Session.getDefaultInstance( fMailServerConfig, null );
    MimeMessage message = new MimeMessage( session );
    try {

      message.addRecipient(
        Message.RecipientType.TO, new InternetAddress(aToEmailAddr)
      );
      message.setSubject( aSubject );
      message.setText( aBody );
      Transport.send( message );
    }
    catch (MessagingException ex){
      System.err.println("Cannot send email. " + ex);
    }
  }


  public static void refreshConfig() {
    fMailServerConfig.clear();
    fetchConfig();
  }



  private static Properties fMailServerConfig = new Properties();

  static {
    fetchConfig();
  }


  private static void fetchConfig() {
    InputStream input = null;
    try {

      input = new FileInputStream( "C:\Temp\MyMailServer.txt" );
      fMailServerConfig.load( input );
    }
    catch ( IOException ex ){
      System.err.println("Cannot open and load mail server properties file.");
    }
    finally {
      try {
        if ( input != null ) input.close();
      }
      catch ( IOException ex ){
        System.err.println( "Cannot close mail server properties file." );
      }
    }
  }
}

How to solve this?

问题回答

Add javax.mail.jar and activation.jar to Go to your project -> Build path -> Configure build path -> Java build path -> libraries.

贵方需要在项目名称上点击项目名称,把去向

Properties-> Libraries -> Press Add Jar/Folder

...... Browse and selected per jar...and/2005/6OK...and

清洁、建设和再经营





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签