⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mytask.java

📁 利用JavaMail实现的发送及接收邮件的程序
💻 JAVA
字号:
package com.digipower.automail.mailsender;import javax.servlet.*;import java.util.*;import com.digipower.automail.AutoMailConstants;import java.io.*;import org.apache.log4j.*;/** * <p>Title: </p> * <p>Description: TestStruts</p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: foxconn</p> * @author conti * @version 1.0 */public class MyTask extends TimerTask {  public MyTask() {  }  private static final int  C_SCHEDULE_HOUR = AutoMailConstants.SCHEDULE_HOUR;  private static boolean isRunning = false;  private ServletContext context = null;  private static Logger		s_log = null;  private static Properties 		s_prop = new Properties();  String strFromAddress = null;  String strReplyAddress = null;  String strReplyToAddress = null;  public MyTask(ServletContext context) {    this.context = context;    s_log = Logger.getLogger(MyTask.class);    PropertyConfigurator.configure(context.getRealPath("/") + "\\WEB-INF\\log4j.inf");  }  public void run() {    Calendar cal = Calendar.getInstance();    try    {      if (!isRunning)      {        FileInputStream fis = null;        try        {                fis = new FileInputStream(context.getRealPath("/") + "\\WEB-INF\\automail.properties");                s_prop.load(fis);                fis.close();        }        catch (FileNotFoundException e)        {          s_log.warn(cal.getTime() + " " + "automail.properties does not exists.");        }        int iTime = 0;        String str = s_prop.getProperty("SendTime");        strFromAddress = s_prop.getProperty("FromAddress");       strReplyAddress = s_prop.getProperty("ReplyAddress");       strReplyToAddress = s_prop.getProperty("ReplyToAddress");        if(str != null)        {          iTime = Integer.parseInt(str);        }System.out.println("iTime:" + iTime);        s_log.warn(cal.getTime() + " " + context.getRealPath("/") + "\\WEB-INF\\automail.properties");        s_log.warn(cal.getTime() + " iTime: " + String.valueOf(iTime));        s_log.warn(cal.getTime() + " " + "FromAddress:" + strFromAddress);        s_log.warn(cal.getTime() + " " + "ReplyAddress:" + strReplyAddress);//        s_log.warn(cal.getTime() + " " + "Manager:" + AutoSend.MANAGER_ADDRESS.length);        if (iTime == cal.get(Calendar.HOUR_OF_DAY))        {          isRunning = true;          //TODO 添加自定义的详细任务,以下只是示例System.out.println("The Listener Running");System.out.println(cal.get(Calendar.HOUR_OF_DAY));//          s_log.warn(cal.getTime() + " " + context.getRealPath("/") + "\\WEB-INF\\automail.properties");//          s_log.warn(cal.getTime() + " " + String.valueOf(iTime));          //send mail action          AutoSend send = new AutoSend();          send.autoSend(strFromAddress, strReplyAddress, strReplyToAddress);          isRunning = false;        }        else        {System.out.println("C_SCHEDULE_HOUR:" + C_SCHEDULE_HOUR);          System.out.println("No Sending");          System.out.println(cal.get(Calendar.HOUR_OF_DAY));        }      }      else      {        System.out.println("No Running");      }    }    catch(Exception e)    {      System.out.println(e);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -