Search in sources :

Example 1 with AlertNoticeException

use of com.usthe.manager.support.exception.AlertNoticeException in project hertzbeat by dromara.

the class EmailAlertNotifyHandlerImpl method send.

@Override
public void send(NoticeReceiver receiver, Alert alert) {
    try {
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
        messageHelper.setSubject("TanCloud探云-监控告警");
        // Set sender Email 设置发件人Email
        messageHelper.setFrom(emailFromUser);
        // Set recipient Email 设定收件人Email
        messageHelper.setTo(receiver.getEmail());
        messageHelper.setSentDate(new Date());
        // Build email templates 构建邮件模版
        String process = mailService.buildAlertHtmlTemplate(alert);
        // Set Email Content Template 设置邮件内容模版
        messageHelper.setText(process, true);
        javaMailSender.send(mimeMessage);
    } catch (Exception e) {
        log.error("[Email Alert] Exception,Exception information={}", e.getMessage());
        throw new AlertNoticeException("[Email Alert] failed: " + e.getMessage());
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) AlertNoticeException(com.usthe.manager.support.exception.AlertNoticeException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) Date(java.util.Date) AlertNoticeException(com.usthe.manager.support.exception.AlertNoticeException)

Aggregations

AlertNoticeException (com.usthe.manager.support.exception.AlertNoticeException)1 Date (java.util.Date)1 MimeMessage (javax.mail.internet.MimeMessage)1 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)1