如何执行我的程序?

时间:2013-02-26 19:13:50

标签: java html eclipse

以下是我的程序的代码。我想从Linux服务器复制一个html文件,并将该发送html文件作为电子邮件正文发送。我正在使用CLASSPATH导入我的jar文件并成功完成编译,但在运行程序时出错。以下是从Linux服务器执行时的错误。 也从Eclipse运行错误。

import java.io.*;
import java.util.*;
//import java.sql.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SendTable1 {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception, IOException{
            try {
                    String host = "127.0.0.1";
                    String from = "ychilukuri@zetainteractive.com";
                    String to = "supalerts@zetainteractive.com";
                    Properties properties = System.getProperties();
                    properties.setProperty("mail.smtp.host",host);
                    Session session = Session.getDefaultInstance(properties);
                    MimeMessage message = new MimeMessage(session);
                    message.setFrom(new InternetAddress(from));
                    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
                    message.setSubject("DataBase table");
                    FileInputStream fst = new FileInputStream("abuses.html");
            int cnt = 0;
                    StringBuffer buffer = new StringBuffer();
                    while ((cnt = fst.read()) != -1 )
                {
                       buffer.append((char) cnt);
                    }
                    message.setText("" +buffer.toString() ,"text/plain");
                    Transport.send(message);
                    System.out.println("message send......");
            }
            catch(Exception ex)  {
            ex.printStackTrace();
            System.out.println("Error :" +ex.getMessage());
            }
        }
    }

汇编:

javac -classpath /home/ebiz40/product/6.1.0/zemo/webapps/zetamobile/WEB-INF/lib/mail.jar /home/ebiz40/SendTable1.java


~]$ java -classpath /home/ebiz40/product/6.1.0/zemo/webapps/zetamobile/WEB-INF/lib/mail.jar /home/ebiz40/SendTable1
Error: Could not find or load main class .home.ebiz40.SendTable1
~]$ java -classpath .:. /home/ebiz40/product/6.1.0/zemo/webapps/zetamobile/WEB-INF/lib/mail.jar  /home/ebiz40/SendTable1
Error: Could not find or load main class .home.ebiz40.product.6.1.0.zemo.webapps.zetamobile.WEB-INF.lib.mail.jar
~]$ java -classpath .  /home/ebiz40/product/6.1.0/zemo/webapps/zetamobile/WEB-INF/lib/mail.jar  /home/ebiz40/SendTable1
Error: Could not find or load main class .home.ebiz40.product.6.1.0.zemo.webapps.zetamobile.WEB-INF.lib.mail.jar

以下是Eclipse的错误:

javax.mail.MessagingException: Could not connect to SMTP host: 127.0.0.1, port: 25;
  nested exception is:
      java.net.ConnectException: Connection refused: connectError :Could not connect to SMTP host: 127.0.0.1, port: 25

      at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1706)
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
      at javax.mail.Service.connect(Service.java:291)
      at javax.mail.Service.connect(Service.java:172)
      at javax.mail.Service.connect(Service.java:121)
      at javax.mail.Transport.send0(Transport.java:190)
      at javax.mail.Transport.send(Transport.java:120)

请让我们知道我在哪里得到错误?怎么解决呢?

0 个答案:

没有答案