emailsubscribejob.java

来自「cwbbs 云网论坛源码」· Java 代码 · 共 97 行

JAVA
97
字号
package cn.js.fan.module.cms.job;import java.util.*;import cn.js.fan.mail.*;import cn.js.fan.module.cms.*;import cn.js.fan.module.cms.Config;import cn.js.fan.module.cms.ext.*;import cn.js.fan.util.*;import cn.js.fan.web.*;import com.cloudwebsoft.framework.util.*;import com.redmoon.forum.person.*;import org.quartz.*;public class EmailSubscribeJob implements Job {    public EmailSubscribeJob() {    }    public void send(String to, String subject, String senderName,                     String content) {        SendMail sendmail = new SendMail();        senderName = StrUtil.GBToUnicode(senderName);        senderName += "<" + Global.getEmail() + ">";        try {            sendmail.initSession(Global.getSmtpServer(), Global.getSmtpPort(),                                 Global.getSmtpUser(), Global.getSmtpPwd());            sendmail.initMsg(to, senderName, subject, content, true);            sendmail.send();        } catch (Exception e) {            LogUtil.getLog(getClass()).error("send:" + e.getMessage());        } finally {            sendmail.clear();        }    }        public void execute(JobExecutionContext jobExecutionContext) throws            JobExecutionException {        UserEmailSubscribeDb uesd = new UserEmailSubscribeDb();        Vector v = uesd.list();        Iterator ir = v.iterator();        Config cfg = new Config();        UserMgr um = new UserMgr();        while (ir.hasNext()) {            uesd = (UserEmailSubscribeDb) ir.next();            String dirCodes = uesd.getString("cms_dirs");            LogUtil.getLog(getClass()).info("execute:dirCodes" + dirCodes);            String moduleCodes = uesd.getString("module_codes");            UserDb user = um.getUser(uesd.getString("user_name"));            String str = "";            String[] d = StrUtil.split(dirCodes, ",");            if (d != null) {                Directory dir = new Directory();                int len = d.length;                Document doc = new Document();                for (int i = 0; i < len; i++) {                    Leaf lf = dir.getLeaf(d[i]);                    if (lf != null && lf.isLoaded()) {                        String query = SQLBuilder.getDirDocListSql(lf.getCode());                        String groupKey = lf.getCode();                                                                        ir = doc.getDocuments(query, groupKey, 0,                                              cfg.                                              getIntProperty(                                "cms.emailSubscribeCount"));                        while (ir.hasNext()) {                            doc = (Document) ir.next();                            str += "<a href='" + Global.getRootPath() +                                    "/doc_show.jsp?id=" + doc.getId() + "'>" +                                    doc.getTitle() + "</a><BR>";                        }                    }                }            }            if (!str.equals(""))                send(user.getEmail(), Global.AppName, Global.AppName, str);            try {                Thread.sleep(5);            } catch (Exception e) {            }        }    }}

⌨️ 快捷键说明

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