}
public synchronized static void sendMail() {
SysMailConfig sysMailConfig = Context.getProcessEngineConfiguration().getSysMailConfig();
MailInfo mailInfoObj = null;
for (MailInfo mailInfo : sysMailConfig.getMailInfo()) {
if (mailInfo.getMailName().equals(sysMailConfig.getSelected())) {
mailInfoObj = mailInfo;
}
}
if (mailInfoObj == null) {
throw new FixFlowException("系统邮件配置错误请检查流程邮件配置!");
}
List<Object> pObjects = new ArrayList<Object>();
//pObjects.add(MailStatus.COMPLETE.toString());
//pObjects.add(MailStatus.FAILURE.toString());
pObjects.add(MailStatus.NOSEND.toString());
SqlCommand sqlCommand = new SqlCommand(Context.getDbConnection());
Pagination pagination = Context.getProcessEngineConfiguration().getDbConfig().getPagination();
String sqlText=pagination.getPaginationSql("SELECT * FROM FIXFLOW_MAIL WHERE MAIL_STATUS=?", 1, 10, "*", null);
List<Map<String, Object>> dataList = sqlCommand.queryForList(sqlText, pObjects);
for (Map<String, Object> mapData : dataList) {
try {
FixMailTo fixMailTo = new FixMailTo();
fixMailTo.persistentInit(mapData);
MailUtil mailUtil = new MailUtil();
mailUtil.setSmtpHost(mailInfoObj.getSmtpHost(), StringUtil.getInt(mailInfoObj.getSmtpPort()));
mailUtil.setSmtpAuthentication(mailInfoObj.getUserName(), mailInfoObj.getPassWord());
// 支持发送多人邮件 #4185
String to = fixMailTo.getMailTo();
if (to == null || to.equals("")) {
throw new FixFlowBizException("mailTo is null");
}
String[] str = to.split(",");
List<String> userMailToList=new ArrayList<String>();
for (String userMail : str) {
if(userMail==null||userMail.equals("")||userMail.trim().equals("")){
}
else{
userMailToList.add(userMail);
}
}
if(userMailToList.size()==0){
throw new FixFlowBizException("Mail toaddress is null");
}
String[] userMailToFinStrings=(String[])userMailToList.toArray(new String[userMailToList.size()]);
mailUtil.setTo(userMailToFinStrings);
String cc = fixMailTo.getMailCc();
if (cc != null && !cc.equals("")) {
String[] strCC = cc.split(",");
List<String> userMailCCList=new ArrayList<String>();
for (String userMail : strCC) {
if(userMail==null||userMail.equals("")||userMail.trim().equals("")){
}
else{
userMailCCList.add(userMail);
}
}
if(userMailCCList.size()==0){
throw new FixFlowBizException("Mail ccaddress is null");
}
String[] userMailCCFinStrings=(String[])userMailCCList.toArray(new String[userMailCCList.size()]);
mailUtil.setCC(userMailCCFinStrings);
}
String title = fixMailTo.getMailSubject();
String mailContent = fixMailTo.getMailBody();
mailUtil.setFrom(mailInfoObj.getMailAddress());
mailUtil.setSubject(title);
mailUtil.setBody(mailContent);
mailUtil.setContentType(mailUtil.MODE_HTML);