public EmailSenderActor(EmailSender emailSender) { if (emailSender == null) { throw new IllegalArgumentException("emailSender must be defined."); } receive( ReceiveBuilder.match( EmailSenderMsg.class, msg -> { try { emailSender.send( msg.to, msg.cc, msg.ci, msg.object, msg.content, msg.htmlContent, msg.attachments); } catch (RuntimeException e) { LOGGER.error( "Unable to sent email to '{}', with subject '{}'", Arrays.toString(msg.to.toArray()), msg.object, e); sender().tell(Futures.failed(e), self()); } if (LOGGER.isDebugEnabled()) { LOGGER.debug( "Email sent to '{}' with subject '{}'", Arrays.toString(msg.to.toArray()), msg.object); } getContext().stop(self()); }) .matchAny(this::unhandled) .build()); }