Search in sources :

Example 1 with Response

use of com.sendgrid.SendGrid.Response in project mxisd by kamax-io.

the class EmailSendGridNotificationHandler method send.

private void send(String recipient, Email email) {
    if (StringUtils.isBlank(cfg.getIdentity().getFrom())) {
        throw new FeatureNotAvailable("3PID Email identity: sender address is empty - " + "You must set a value for notifications to work");
    }
    try {
        email.addTo(recipient);
        email.setFrom(cfg.getIdentity().getFrom());
        email.setFromName(cfg.getIdentity().getName());
        Response response = sendgrid.send(email);
        if (response.getStatus()) {
            log.info("Successfully sent email to {} using SendGrid", recipient);
        } else {
            throw new RuntimeException("Error sending via SendGrid to " + recipient + ": " + response.getMessage());
        }
    } catch (SendGridException e) {
        throw new RuntimeException("Unable to send e-mail invite via SendGrid to " + recipient, e);
    }
}
Also used : FeatureNotAvailable(io.kamax.mxisd.exception.FeatureNotAvailable) Response(com.sendgrid.SendGrid.Response) SendGridException(com.sendgrid.SendGridException)

Example 2 with Response

use of com.sendgrid.SendGrid.Response in project mxisd by kamax-io.

the class EmailSendGridNotificationHandler method send.

private void send(String recipient, Email email) {
    if (StringUtils.isBlank(cfg.getIdentity().getFrom())) {
        throw new FeatureNotAvailable("3PID Email identity: sender address is empty - " + "You must set a value for notifications to work");
    }
    try {
        email.addTo(recipient);
        email.setFrom(cfg.getIdentity().getFrom());
        email.setFromName(cfg.getIdentity().getName());
        Response response = sendgrid.send(email);
        if (response.getStatus()) {
            log.info("Successfully sent email to {} using SendGrid", recipient);
        } else {
            throw new RuntimeException("Error sending via SendGrid to " + recipient + ": " + response.getMessage());
        }
    } catch (SendGridException e) {
        throw new RuntimeException("Unable to send e-mail invite via SendGrid to " + recipient, e);
    }
}
Also used : FeatureNotAvailable(io.kamax.mxisd.exception.FeatureNotAvailable) Response(com.sendgrid.SendGrid.Response) SendGridException(com.sendgrid.SendGridException)

Aggregations

Response (com.sendgrid.SendGrid.Response)2 SendGridException (com.sendgrid.SendGridException)2 FeatureNotAvailable (io.kamax.mxisd.exception.FeatureNotAvailable)2