Exemplo n.º 1
0
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    if (obj instanceof Body == false) return false;
    Body other = (Body) obj;
    if (other.getText() == null ^ this.getText() == null) return false;
    if (other.getText() != null && other.getText().equals(this.getText()) == false) return false;
    if (other.getHtml() == null ^ this.getHtml() == null) return false;
    if (other.getHtml() != null && other.getHtml().equals(this.getHtml()) == false) return false;
    return true;
  }
Exemplo n.º 2
0
  @Override
  public void sendEmail(EmailBean emailBean) {

    if (emailBean == null) {
      return;
    }

    if (CollectionUtils.isEmpty(emailBean.getRecipients())) {
      return;
    }

    final Destination destination = new Destination().withToAddresses(emailBean.getRecipients());
    final Content subjectContent = new Content().withData(emailBean.getSubject());
    final Content bodyContent = new Content().withData(emailBean.getBody());
    final Body body = new Body().withText(bodyContent);

    if (StringUtils.hasText(emailBean.getRecordsAsHtml())) {
      body.withHtml(new Content().withData(emailBean.getRecordsAsHtml()));
    }

    final Message message = new Message().withSubject(subjectContent).withBody(body);

    final SendEmailRequest request =
        new SendEmailRequest()
            .withSource(emailBean.getFrom())
            .withDestination(destination)
            .withMessage(message);

    final AmazonSimpleEmailServiceClient emailClient = new AmazonSimpleEmailServiceClient();
    final Region region = Region.getRegion(Regions.DEFAULT_REGION);
    emailClient.setRegion(region);

    SendEmailResult sendEmailResult = emailClient.sendEmail(request);

    //        TODO handle email result (Log, store state to db, etc..)
  }