java를 crontab실행시 메일발송 문제....
jdbc연동이 해결되니 다른문제가..
오라클 jdbc연동으로 값을가져와 메일발송 java프로그램을 만들었습니다.
그냥 java실행하면 메일발송까지 모두 잘 됩니다.
crontab 실행을 위해 sh파일을 만들었습니다.근데 메일발송이 안되구요
로그에 아래와같은 에러가....ㅜㅜ 호스트를 지정해줬는데 못찾아요..
어떻게 해야 되는지 제발 알려주시면 정말정말 감사하겠습니다.
==========에러 ===========================
Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused
===========================================
===test.sh====(classpath모두 잡아주었습니다.)
#!/usr/local/bin/bash
JAVA_HOME=/usr/local/java1.3
export JAVA_HOME
TOMCAT_HOME=/usr/local/jakarta_project/jakarta-tomcat-3.2.1
export TOMCAT_HOME
export JACARTA_HOME=/usr/local/jakarta_project
export STRUTS_HOME=$JACARTA_HOME/jakarta-struts-1.0-b1
export CLASSPATH=$CLASSPATH:$JACARTA_HOME/jakarta-tomcat-3.2.1/lib/ant.jar:
export CLASSPATH=$CLASSPATH:/usr/local/java1.3/lib/mail.jar:
export CLASSPATH=$CLASSPATH:/usr/local/java1.3/lib/activation.jar:
...... classpath 이하 중략......
/usr/local/java1.3/bin/java -cp $CLASSPATH:/usr/local/jakarta_project/SOURCE/ICBS_SRC/Work/order/mail_send_log/Mail_schedule.jar Mail_schedule
========== Mail_schedule.java=========================================
public class Mail_schedule
{
private String host = "xxx.net"; //호스트
private String to = null;
private String tname = null;
private String from = null;
private String fname = null;
private String msgSubj = null;
private String msgText = null;
private String path = null;
private String filename = null;
private Message msg = null;
Properties props = new Properties();
Session sess = Session.getDefaultInstance(props, null);
public void setMail(String to, String tname, String from, String fname, String msgSubj, String msgText, String path, String filename ) {
this.to = to;
this.tname = tname;
this.from = from;
this.fname = fname;
this.msgSubj = msgSubj;
this.msgText = msgText;
this.path = path;
this.filename = filename;
}
public boolean send_boolean() {
boolean retValue = false;
try {
props.put("mail.smtp.host", host);
// create a message
InternetAddress address = new InternetAddress(to, tname, "EUC-KR");
InternetAddress fadd = new InternetAddress(from, fname, "EUC-KR");
java.util.Date curdate = new java.util.Date();
java.sql.Date sqldate = new java.sql.Date(curdate.getTime());
msg = new MimeMessage(sess);
msg.setFrom(fadd);
msg.setRecipient(Message.RecipientType.TO, address);
msg.setSubject(msgSubj);
msg.setSentDate(sqldate);
msg.setContent(msgText,"text/html;charset=euc-kr"); // HTML type
Transport.send(msg);
retValue = true;
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("
can't use "+host+"");
} // end try
return retValue;
}
public Mail_schedule(String mail_id, String send_gubun){
this.mail_id = mail_id;
this.send_gubun = send_gubun;
}
public void All_send() {
try
{
......... 이하 중략 .........
} catch (SQLException e){
e.printStackTrace();
}catch ( Exception e ) {
}
}
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 선택고객발송
public void each_send() {
try {
......... 이하 중략 .........
//메일발송
Mail_schedule mb = new Mail_schedule(mail_id,send_gubun);
mb.setMail(rs2.getString("email"), tname, mailFrom, mailFrom, mailTitle, template2,fileurl,filename);
boolean retV = true;
retV = mb.send_boolean();
......... 이하 중략 .........
} catch (SQLException e){
e.printStackTrace();
}catch ( Exception e ) {
}
}
public static void main (String[] argv)
{
try {
String sqlQuery = " select * from mail_send_log where appoint_date = to_date(sysdate,'YY-mm-dd') and is_send=0 ";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String strUrl = "jdbc:oracle:thin:@1.1.1.1:1521:ELIM";
//Oracle JDBC Driver Load
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection( strUrl , "userid" , "pass" );
stmt = conn.createStatement();
rs = stmt.executeQuery( sqlQuery );
while(rs.next()) {
String mail_id = rs.getString("mail_id");
String send_gubun =rs.getString("send_gubun");
if(rs.getString("serviceid_value") == null|| rs.getString("serviceid_value").equals("")) {
Mail_schedule th = new Mail_schedule(mail_id,send_gubun);
th.All_send ();
}else {
Mail_schedule th = new Mail_schedule(mail_id,send_gubun);
th.each_send ();
}
}//while(rs.next
} catch (SQLException e){
e.printStackTrace();
}catch ( Exception e ) {
}
}
}
댓글 달기