Below is code for my program. i want to copy an html file from a linux server and send that send html file as email body. i am importing my jar file using CLASSPATH and completed compilation successfully but getting error while running program. below are the error while executing from Linux sever. also getting error running from Eclipse also.
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());
}
}
}
compilation:
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
Below is the error from 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)
Please let us knwo where i am getting error? how to solve it?