0

下面是我的程序的代码。我想从 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)

请让我们知道我在哪里出错?如何解决?

4

0 回答 0