1.背景介绍:公司10多年一直做oracle ilearning的实施,oracle是不提供源码的,我们只能靠自己反编译、继承等一些手段来实现客户化,系统发送邮件功能有一个配置文件可配置,但是要求不验证邮箱密码通过javamail发送邮件。之前我们面对的客户主要的都是一些大型企业客户,他们一般都有自己的邮件服务器,在邮件服务器上做一下设置就行,但是目前一些客户一般都使用网易、腾讯等企业邮箱,这些供应商一般不会提供免验证发送邮件的。这就需要我们解决这个问题,有两个方案:一、自己搭建一个邮件服务器。二、修改oracle ilearning原始发送邮件功能的代码。
2.进入正题:我这边使用Apache的James mail自己搭建过邮件服务器。但自己搭建邮件代价较大,这里说一下如何修改原始功能代码使用javamail发送邮件。
oracle ilearning邮件发送功能的配置在 ~WEB-INF/ilearning.properties文件中
# ******************************************************************* #Example: MAIL_HOST=smtp02.us.oracle.com MAIL_HOST=smtp.163.com #ADMIN_EMAIL: The email address where system generated emails will be sent from #Recommendation: set to valid email address #Default setting: nobody@<domain> #Example: ADMIN_EMAIL=admin@mycompany.com #This email account is used for forgot password emails. Bounced emails #will be returned to this address. ADMIN_EMAIL=admin@163.com
MAIL_HOST对应的是邮件服务器发送地址,ADMIN_EMAIL是发件人。
那么oracle ilearning 原始代码是怎么调用的呢?没有源码,只有通过简单的找回密码功能一步一步一层一层的找。终于使用强大的MyEclipse反编译工具插件(附件可下载),找到邮件发送类:oracle.ila.common.collaboration.email.EmailUtil。以下是反编译出来的部分代码
//发送失败后重复尝试发送的次数 public static final int RESEND_EMAIL = 5; //构造函数 public EmailUtil() { Properties props = setMailHost(); this.session = Session.getDefaultInstance(props, null); this.msg = new MimeMessage(this.session); } //设置smtp邮件发送地址配置 private Properties setMailHost(){ Properties _props = new Properties(); _props.put("mail.smtp.host", ILAProperties.getMailHost()); return _props; } //具体的发送逻辑代码 private void transportMessageToMailer(boolean forceSend) throws SendFailedException, MessagingException{ SendFailedException lastError = null; int count = 0; for (int i = 0; i < 5; ++count) { lastError = null; try { Transport.send(this.msg); } catch (SendFailedException es) { Address[] validUnsent = es.getValidUnsentAddresses(); Address[] vailidSent = es.getValidSentAddresses(); Address[] InvalidAddress = es.getInvalidAddresses(); if ((validUnsent == null) && (validUnsent == null) && (InvalidAddress == null)) { lastError = es; } else { if ((forceSend) && (validUnsent != null)) { Transport.send(this.msg, validUnsent); throw new SendFailedException(es.getMessage(), es, validUnsent, null, es.getInvalidAddresses()); } throw es; } } ++i; } if (lastError != null) { Logger.error("EmailUtil ->transportMessageToMailer: SMTP Connection Failed - Have tried " + Integer.toString(count) + " times to send message"); throw lastError; } }
以上反编译的结果肯定会和源码有些差别的,很明显的错误需要修改一下即可。那么我们就来说说,如何修改可实现配置验证邮箱密码发送邮件。
第一步,检查反编译出来的代码是否有错,解决明显的错误,可能大家会忽视下面一个错误:
private void transportMessageToMailer(boolean forceSend) throws SendFailedException, MessagingException { SendFailedException lastError = null; int count = 0; //发编译的结果常量直接变成了具体的值 for (int i = 0; i < 5; ++count) { for (int i = 0; i < RESEND_EMAIL; ++count) { lastError = null; try { Transport.send(this.msg); //这里很明显漏了一个return ,如果不加return那么系统会一次性发送5封相同的邮件。下面加上 return; } catch (SendFailedException es) { Address[] validUnsent = es.getValidUnsentAddresses(); Address[] vailidSent = es.getValidSentAddresses(); Address[] InvalidAddress = es.getInvalidAddresses(); if ((validUnsent == null) && (validUnsent == null) && (InvalidAddress == null)) { lastError = es; } else { if ((forceSend) && (validUnsent != null)) { Transport.send(this.msg, validUnsent); throw new SendFailedException(es.getMessage(), es, validUnsent, null, es.getInvalidAddresses()); } throw es; } } ++i; } if (lastError != null) { Logger.error("EmailUtil ->transportMessageToMailer: SMTP Connection Failed - Have tried " + Integer.toString(count) + " times to send message"); throw lastError; } }
第二步,自己创建添加一个javamail的验证类
import javax.mail.Authenticator; import javax.mail.PasswordAuthentication; /** * @author Chan Lewis * @version 2014-3-24 */ public class MyAuthenticator extends Authenticator{ String userName = null; String password = null; public MyAuthenticator() { } public MyAuthenticator(String username, String password) { this.userName = username; this.password = password; } protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); } }
第三步,修改邮件的初始化配置
//构造函数 public EmailUtil(){ Properties props = setMailHost(); //是否验证密码,可在ilearning.properties中添加配置 String isValidateStr = ILAProperties.getProperty("SMTP_AUTH"); if(null!=isValidateStr && "true".equalsIgnoreCase(isValidateStr)){ //如果验证密码 //添加初始化配置 props.put("mail.smtp.port", "25"); props.put("mail.smtp.auth", "true"); MyAuthenticator authenticator = new MyAuthenticator(ILAProperties.getProperty("ADMIN_EMAIL"), ILAProperties.getProperty("ADMIN_PASSWORD")); this.session = Session.getDefaultInstance(props, authenticator); }else{ //如果不验证密码 this.session = Session.getDefaultInstance(props, null); } this.msg = new MimeMessage(this.session); }
ilearning.properties中添加相关配置SMTP_AUTH 、ADMIN_PASSWORD
# ******************************************************************* #Example: MAIL_HOST=smtp02.us.oracle.com MAIL_HOST=smtp.163.com SMTP_AUTH=true #ADMIN_EMAIL: The email address where system generated emails will be sent from #Recommendation: set to valid email address #Default setting: nobody@<domain> #Example: ADMIN_EMAIL=admin@mycompany.com #This email account is used for forgot password emails. Bounced emails #will be returned to this address. ADMIN_EMAIL=admin@163.com ADMIN_PASSWORD=password #******************************************************************************
OK到此为止就修改完成了。这样修改之后,既可以使用javamail不验证发送邮件,也可以验证用户名密码发送邮件,具体可在ilearning.properties文件里面配置。
3.问题答疑:有些新手可能还会问,我这边反编译后怎么替换原始功能呢?
答:原始的功能除oracle官方发布的补丁之外,一般都打包在ilearning.jar中,主要看你现在使用的web服务器,一般买了oracle ilearning的基本都是使用oracle IAS服务器的,所以把自己修改的java文件生成类文件放到对应的目录即可。另外一种办法是通过打包技术把生成的类文件重新打包到ilearning.jar(不建议使用)。
相关推荐
Oracle iLearning 5.0 产品综述. Oracle iLearning是一种企业级的学习管理系统,可作为订阅服务或发放许可的产品来提供。其中,订阅服务具有使用方便和费用低廉的特点,它通过Web提供个性化教育,是一种可在整个...
宝钢上马Oracle iLearning网络培训系统.pdf
提高培训质量和效率 降低培训管理成本 有力支撑人才发展 Oracle iLearning构筑宝钢网络培训系统.pdf
ilearning配置类,防止ilearning类中的丢失国际化,需要重新编译此文件。
ilearning-view 集成学习环境,视图层
基于RxJava 的函数式 Reactive 风格的 Java web 框架。... Server server = new Server( rb -> rb.ifMethodAndUriMatch(Method.GET, "/status", r -> r.respond(b -> b.ok())) ....
2012届华为校园招聘上机考试题.docx
回教锈
OTN硬件介绍,OTN是光纤远距离传输的应用设备,掌握OTN技术是对光纤传输的技术升级。
东航庞大的高质量要求的培训目标的实现,告诉我们:当企业对iLearning——在线学习管理系统有了足够的认识之后,企业迈向教育培训信息化的步伐也就加速了,自然也加快了企业成长的步伐。目前,东方航空在企业的教育...
OD和正式员工的工作内容完全一致,而且还有内部的wiki社区、ilearning学习平台等,可以提供较大的成长空间。 此外,OD员工在华为工作满一年之后,可以根据部门OD比例、是否来自目标院校、个人工作表现等因素来决定...
iLearning 实验室的脚本库请使用 .lsl 扩展名保存文件,以便它们可以导入到第二人生