@Override
public void send(final Email email) throws SendGridException {
if (email == null) {
throw new IllegalArgumentException("[email] cannot be null");
}
LOG.debug("Sending to SendGrid client: FROM {}<{}>", email.getFromName(), email.getFrom());
LOG.debug("Sending to SendGrid client: TO {} (as {})", email.getTos(), email.getToNames());
LOG.debug("Sending to SendGrid client: SUBJECT {}", email.getSubject());
LOG.debug("Sending to SendGrid client: TEXT CONTENT {}", email.getText());
LOG.debug("Sending to SendGrid client: HTML CONTENT {}", email.getHtml());
initSendGridClient();
final SendGrid.Response response = delegate.send(email);
if (response.getStatus()) {
LOG.debug("Response from SendGrid client: ({}) {}", response.getCode(), response.getMessage());
} else {
throw new SendGridException(new IOException("Sending to SendGrid failed: (" + response.getCode() + ") " + response.getMessage()));
}
}