@RequestMapping(value = "/testSendMail.jspx", method = RequestMethod.GET)
public void testSendMail(HttpServletRequest request, HttpServletResponse respone) {
Website web = SiteUtils.getWeb(request);
//final EmailSender email = web.getEmailSender();
final MessageTemplate tpl = (MessageTemplate) web.getMessages().get(MessageTemplate.RESET_PASSWORD);
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost("smtp.aliyun.com");
sender.setUsername("
tang.xin@gzstone.com.cn");
sender.setPassword("********");//发帖时故意隐藏
sender.send(new MimeMessagePreparator() {
public void prepare(MimeMessage mimemessage) {
try {
MimeMessageHelper msg = new MimeMessageHelper(mimemessage, false, "UTF-8");
msg.setSubject("这是一份测试邮件");
msg.setTo("
1292785717@qq.com");
msg.setFrom("Sender", "Sender");
String text = tpl.getActiveTxt();
text = StringUtils.replace(text, "${userName}","testUser01");
text = StringUtils.replace(text, "${usernameId}", "1");
text = StringUtils.replace(text, "${activationCode}", "1236585");
text = StringUtils.replace(text, "${base}", "Base");
msg.setText(text,true);
} catch(Exception e) {
e.printStackTrace();
}
}
});
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。