开发用例

邮件发送

邮件发送驱动器EmailProcessor相关实现代码

_webParams.getSessionItem().remove(' functiongetDateTime(myDate){
         var year=myDate.getFullYear();
         var month=myDate.getMonth()+1;
         var date=myDate.getDate();
         var hour = myDate.getHours();       //获取当前小时数(0-23)
         var minute = myDate.getMinutes();     //获取当前分钟数(0-59)
         var seconds = myDate.getSeconds();     //获取当前秒数(0-59)
         if(month<10){
                   month="0"+month;
         }
         if(date<10){
                   date="0"+date;
         }
         if(hour<10){
                   hour="0"+hour;
         }
         if(minute<10){
                   minute="0"+minute;
         }
         if(seconds<10){
                   seconds="0"+seconds;
         }
    var currentTime=year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + seconds;     
    return currentTime;
}

//获取失效时间参数:小时
functiongetInvalidDate(hour){
         var date1=new Date();  //开始时间
         var date2 = new Date(date1.getTime() + hour*60*60*1000);
         return date2;
}
function sendEmail(userEmail, subject, htmlMessage, textMessage){
         var toMailAddress = userEmail;      
         var smtpAccountName = "demo@cms.com";
         var smtpPassword = "123456";
         var smtpServerAddress = "smtp.exmail.qq.com";
         var smtpServerPort = 465;
         var isSSL = true;
         var fromMailAddress = "demo@cms.com";
         _mail.sendMail(smtpAccountName,
smtpPassword,
smtpServerAddress,
smtpServerPort,
isSSL,
fromMailAddress,
toMailAddress,
subject,
htmlMessage,
textMessage);
         var sendTime = new Date().getTime().toString();
         var cols = ["toMailAddress","fromMailAddress","sendTime","type","status","subject","provider","content"];
         var vals = [toMailAddress,fromMailAddress,sendTime.toString(),"VERIFY","0",subject,"无",htmlMessage];
          _db.updateData('cms', 'EmailRecord',cols, vals);
}USER_CACHE ');

模板页面发送邮件代码

//发送验证链接
function sendActiveUserEmail(userName, email){
    var currentTime = getDateTime(new Date());
    var invalidDate = getInvalidDate(1);
    var showInvalidTime =  getDateTime(invalidDate);
    var invaliDateTime = invalidDate.getTime()+"";
    var verificateCode =  _security.encryptSHA(_webTools.randomAlphanumeric(8));
    var resetPassword = _webTools.randomAlphanumeric(6);
    var cols = ["userName", "verificateCode", "createTime","invalidTime","validStatus", "type"];
    var vals = [userName, verificateCode,  currentTime, invaliDateTime, true, "NEWUSERACTIVE"];
    _db.updateData('cms','EmailVerificatRecord',cols,vals);
    var siteDomain = "jdf.unitedbiz.net";
try{
         siteDomain = _db.findData("cms","SystemConfig", "domain").get("value");
}catch(e){}

var returnClickUrl = "http://"+ siteDomain +"/activeUserService?username=" + userName  + "&verificateCode=" + verificateCode;

var subject = "激活您的帐户";
         var htmlMessage = '亲爱的用户 '+ userName +':您好!感谢您注册了我们的网站我们将一如既往、热忱的为您服务!';
         var textMessage = "激活帐户";
     sendEmail(email, subject, htmlMessage, textMessage);
}