All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ltsopensource.alarm.email.EmailAlarmNotifier Maven / Gradle / Ivy

package com.github.ltsopensource.alarm.email;

import com.github.ltsopensource.alarm.AbstractAlarmNotifier;
import com.github.ltsopensource.alarm.AlarmNotifyException;
import com.github.ltsopensource.core.AppContext;
import com.github.ltsopensource.core.cluster.Config;

/**
 * @author Robert HG ([email protected])  on 2/17/16.
 */
public class EmailAlarmNotifier extends AbstractAlarmNotifier {

    private MailManager mailManager;

    public EmailAlarmNotifier(AppContext appContext) {
        this.mailManager = getMailManager(appContext);
    }

    private MailManager getMailManager(AppContext appContext) {
        Config config = appContext.getConfig();
        String host = config.getParameter("mail.smtp.host");
        String port = config.getParameter("mail.smtp.port");
        String userName = config.getParameter("mail.username");
        String password = config.getParameter("mail.password");
        String adminAddress = config.getParameter("mail.adminAddress");
        boolean sslEnabled = config.getParameter("mail.sslEnabled", true);
        return new SMTPMailManagerImpl(host, port, userName, password, adminAddress, sslEnabled);
    }

    @Override
    protected void doNotice(EmailAlarmMessage message) {
        try {
            mailManager.send(message.getTo(), message.getTitle(), message.getMsg());
        } catch (Exception e) {
            throw new AlarmNotifyException("EmailAlarmNotifier send error", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy