use of com.dimple.project.system.domain.EmailSetting in project DimpleBlog by martin-chips.
the class EmailServiceImpl method sendHtmlMail.
@Override
public void sendHtmlMail(String to, String title, String content) {
EmailSetting emailSetting = configService.selectConfigByConfigKey(ConfigKey.CONFIG_KEY_EMAIL_SETTING, EmailSetting.class);
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setUsername(emailSetting.getUser());
mailSender.setHost(emailSetting.getHost());
mailSender.setDefaultEncoding("utf-8");
mailSender.setPassword(emailSetting.getPassword());
mailSender.setPort(emailSetting.getPort());
Properties properties = new Properties();
properties.put("mail.smtp.host", emailSetting.getHost());
properties.put("mail.smtp.auth", "true");
// 只处理SSL的连接,对于非SSL的连接不做处理
properties.put("mail.smtp.socketFactory.fallback", "false");
properties.put("mail.smtp.port", emailSetting.getPort());
properties.put("mail.smtp.socketFactory.port", emailSetting.getPort());
properties.put("mail.smtp.ssl.enable", true);
Session session = Session.getInstance(properties);
MimeMessage mimeMessage = mailSender.createMimeMessage();
try {
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
mimeMessageHelper.setFrom(emailSetting.getFromEmail());
mimeMessageHelper.setTo(to);
if (StringUtils.isNotEmpty(emailSetting.getStationmasterEmail())) {
mimeMessageHelper.setBcc(emailSetting.getStationmasterEmail());
}
mimeMessageHelper.setSubject(title);
mimeMessageHelper.setText(content, true);
mailSender.setSession(session);
mailSender.send(mimeMessage);
} catch (MessagingException e) {
log.error(e.getMessage(), e);
}
}
use of com.dimple.project.system.domain.EmailSetting in project DimpleBlog by martin-chips.
the class SettingController method emailSetting.
@GetMapping("/emailSetting")
@PreAuthorize("@permissionService.hasPermission('system:setting:emailSetting:query')")
public AjaxResult emailSetting() {
Config config = configService.selectConfigByKey(ConfigKey.CONFIG_KEY_EMAIL_SETTING);
// convert to site setting
if (config != null) {
EmailSetting emailSetting = JSON.parseObject(config.getConfigValue(), EmailSetting.class);
emailSetting.setPassword("*************************");
return AjaxResult.success(emailSetting);
}
return AjaxResult.success(new EmailSetting());
}
Aggregations