Search in sources :

Example 1 with MailAddress

use of org.apache.cloudstack.utils.mailing.MailAddress in project cloudstack by apache.

the class AlertManagerImpl method sendAlert.

public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long clusterId, String subject, String content) throws MessagingException, UnsupportedEncodingException {
    logger.warn(String.format("alertType=[%s] dataCenterId=[%s] podId=[%s] clusterId=[%s] message=[%s].", alertType, dataCenterId, podId, clusterId, subject));
    AlertVO alert = null;
    if ((alertType != AlertManager.AlertType.ALERT_TYPE_HOST) && (alertType != AlertManager.AlertType.ALERT_TYPE_USERVM) && (alertType != AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER) && (alertType != AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY) && (alertType != AlertManager.AlertType.ALERT_TYPE_SSVM) && (alertType != AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC) && (alertType != AlertManager.AlertType.ALERT_TYPE_MANAGMENT_NODE) && (alertType != AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED) && (alertType != AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED) && (alertType != AlertManager.AlertType.ALERT_TYPE_OOBM_AUTH_ERROR) && (alertType != AlertManager.AlertType.ALERT_TYPE_HA_ACTION) && (alertType != AlertManager.AlertType.ALERT_TYPE_CA_CERT)) {
        alert = _alertDao.getLastAlert(alertType.getType(), dataCenterId, podId, clusterId);
    }
    if (alert == null) {
        AlertVO newAlert = new AlertVO();
        newAlert.setType(alertType.getType());
        newAlert.setSubject(subject);
        newAlert.setContent(content);
        newAlert.setClusterId(clusterId);
        newAlert.setPodId(podId);
        newAlert.setDataCenterId(dataCenterId);
        newAlert.setSentCount(1);
        newAlert.setLastSent(new Date());
        newAlert.setName(alertType.getName());
        _alertDao.persist(newAlert);
    } else {
        logger.debug("Have already sent: " + alert.getSentCount() + " emails for alert type '" + alertType + "' -- skipping send email");
        return;
    }
    if (ArrayUtils.isEmpty(recipients)) {
        logger.warn(String.format("No recipients set in global setting 'alert.email.addresses', " + "skipping sending alert with subject [%s] and content [%s].", subject, content));
        return;
    }
    SMTPMailProperties mailProps = new SMTPMailProperties();
    mailProps.setSender(new MailAddress(senderAddress));
    mailProps.setSubject(subject);
    mailProps.setContent(content);
    mailProps.setContentType("text/plain");
    Set<MailAddress> addresses = new HashSet<>();
    for (String recipient : recipients) {
        addresses.add(new MailAddress(recipient));
    }
    mailProps.setRecipients(addresses);
    sendMessage(mailProps);
}
Also used : MailAddress(org.apache.cloudstack.utils.mailing.MailAddress) SMTPMailProperties(org.apache.cloudstack.utils.mailing.SMTPMailProperties) Date(java.util.Date) HashSet(java.util.HashSet)

Example 2 with MailAddress

use of org.apache.cloudstack.utils.mailing.MailAddress in project cloudstack by apache.

the class ProjectManagerImpl method sendInvite.

protected void sendInvite(String token, String email, long projectId) throws MessagingException, UnsupportedEncodingException {
    String subject = String.format("You are invited to join the cloud stack project id=[%s].", projectId);
    String content = String.format("You've been invited to join the CloudStack project id=[%s]. Please use token [%s] to complete registration", projectId, token);
    SMTPMailProperties mailProperties = new SMTPMailProperties();
    mailProperties.setSender(new MailAddress(senderAddress));
    mailProperties.setSubject(subject);
    mailProperties.setContent(content);
    mailProperties.setContentType("text/plain");
    Set<MailAddress> addresses = new HashSet<>();
    addresses.add(new MailAddress(email));
    mailProperties.setRecipients(addresses);
    mailSender.sendMail(mailProperties);
}
Also used : MailAddress(org.apache.cloudstack.utils.mailing.MailAddress) SMTPMailProperties(org.apache.cloudstack.utils.mailing.SMTPMailProperties) HashSet(java.util.HashSet)

Example 3 with MailAddress

use of org.apache.cloudstack.utils.mailing.MailAddress in project cloudstack by apache.

the class UsageAlertManagerImpl method sendAlert.

@Override
public void sendAlert(AlertType alertType, long dataCenterId, Long podId, String subject, String content) {
    AlertVO alert = null;
    if ((alertType != AlertManager.AlertType.ALERT_TYPE_HOST) && (alertType != AlertManager.AlertType.ALERT_TYPE_USERVM) && (alertType != AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER) && (alertType != AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY) && (alertType != AlertManager.AlertType.ALERT_TYPE_SSVM) && (alertType != AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC) && (alertType != AlertManager.AlertType.ALERT_TYPE_MANAGMENT_NODE)) {
        alert = _alertDao.getLastAlert(alertType.getType(), dataCenterId, podId);
    }
    if (alert == null) {
        AlertVO newAlert = new AlertVO();
        newAlert.setType(alertType.getType());
        newAlert.setSubject(subject);
        newAlert.setPodId(podId);
        newAlert.setDataCenterId(dataCenterId);
        newAlert.setSentCount(1);
        newAlert.setLastSent(new Date());
        newAlert.setName(alertType.getName());
        _alertDao.persist(newAlert);
    } else {
        logger.debug(String.format("Have already sent [%s] emails for alert type [%s] -- skipping send email.", alert.getSentCount(), alertType));
        return;
    }
    SMTPMailProperties mailProps = new SMTPMailProperties();
    mailProps.setSender(new MailAddress(senderAddress));
    mailProps.setSubject(subject);
    mailProps.setContent(content);
    mailProps.setContentType("text/plain");
    if (ArrayUtils.isEmpty(recipients)) {
        logger.warn(String.format("No recipients set in global setting 'alert.email.addresses', " + "skipping sending alert with subject [%s] and content [%s].", subject, content));
        return;
    }
    Set<MailAddress> addresses = new HashSet<>();
    for (String recipient : recipients) {
        addresses.add(new MailAddress(recipient));
    }
    mailProps.setRecipients(addresses);
    mailSender.sendMail(mailProps);
}
Also used : AlertVO(com.cloud.alert.AlertVO) MailAddress(org.apache.cloudstack.utils.mailing.MailAddress) SMTPMailProperties(org.apache.cloudstack.utils.mailing.SMTPMailProperties) Date(java.util.Date) HashSet(java.util.HashSet)

Example 4 with MailAddress

use of org.apache.cloudstack.utils.mailing.MailAddress in project cloudstack by apache.

the class QuotaAlertManagerImpl method sendQuotaAlert.

protected void sendQuotaAlert(String accountUuid, List<String> emails, String subject, String body) {
    SMTPMailProperties mailProperties = new SMTPMailProperties();
    mailProperties.setSender(new MailAddress(senderAddress));
    mailProperties.setSubject(subject);
    mailProperties.setContent(body);
    mailProperties.setContentType("text/html; charset=utf-8");
    if (CollectionUtils.isEmpty(emails)) {
        s_logger.warn(String.format("Account [%s] does not have users with email registered, " + "therefore we are unable to send quota alert email with subject [%s] and content [%s].", accountUuid, subject, body));
        return;
    }
    Set<MailAddress> addresses = new HashSet<>();
    for (String email : emails) {
        addresses.add(new MailAddress(email));
    }
    mailProperties.setRecipients(addresses);
    mailSender.sendMail(mailProperties);
}
Also used : MailAddress(org.apache.cloudstack.utils.mailing.MailAddress) SMTPMailProperties(org.apache.cloudstack.utils.mailing.SMTPMailProperties) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)4 MailAddress (org.apache.cloudstack.utils.mailing.MailAddress)4 SMTPMailProperties (org.apache.cloudstack.utils.mailing.SMTPMailProperties)4 Date (java.util.Date)2 AlertVO (com.cloud.alert.AlertVO)1