private void sendEmailIfRequired(final BillingState billingState, final Account account,
final OverdueState nextOverdueState, final InternalTenantContext context) {
if (nextOverdueState.getEnterStateEmailNotification() == null) {
return;
}
final List<String> to = ImmutableList.<String>of(account.getEmail());
final List<String> cc = ImmutableList.<String>of();
final String subject = nextOverdueState.getEnterStateEmailNotification().getSubject();
try {
final String emailBody = overdueEmailGenerator.generateEmail(account, billingState, account, nextOverdueState);
if (nextOverdueState.getEnterStateEmailNotification().isHTML()) {
emailSender.sendHTMLEmail(to, cc, subject, emailBody);
} else {
emailSender.sendPlainTextEmail(to, cc, subject, emailBody);
}
} catch (IOException e) {
log.warn(String.format("Unable to generate or send overdue notification email for account %s and overdueable %s", account.getId(), account.getId()), e);
} catch (EmailApiException e) {
log.warn(String.format("Unable to send overdue notification email for account %s and overdueable %s", account.getId(), account.getId()), e);
} catch (MustacheException e) {
log.warn(String.format("Unable to generate overdue notification email for account %s and overdueable %s", account.getId(), account.getId()), e);
}
}