Interface MailService

All Known Implementing Classes:
MailServiceImpl

public interface MailService
Interface provides basic operations for sending mail messages and mail service configuration data retrieval. Defines synchronous and asynchronous methods responsible for sending mail message. They can receive parameters of different types to create a mail send. You can pass Message, MimeMessage or specify mail message data explicitly via String parameters.
  • Method Details

    • getMailSession

      javax.mail.Session getMailSession()
      Provides Session instance, which is to be used throughout MailService methods
      Returns:
      Session
    • getOutgoingMailServer

      String getOutgoingMailServer()
      Provides outgoing server information, which is basically its hostname or ip address. This server is used as transceiver for mail messages. MailService should send message to the server first and than server will resend messages to the receivers.
      Returns:
    • sendMessage

      void sendMessage(String from, String to, String subject, String body) throws Exception
      Sends mail message based on passed String parameters.
      Parameters:
      from - - String identificator of mail sender. For example 'test.sender@test.test'
      to - - String identificator of mail receiver. For example 'test.receiver@test.test'
      subject - - String subject of mail message
      body - - String contents of mail message
      Throws:
      Exception - is thrown if something's gone wrong during mail send procedure
    • sendMessage

      void sendMessage(Message message) throws Exception
      Sends mail message based on Message instance
      Parameters:
      message - - Message provides mail message related data (e.g. subject, content etc.)
      Throws:
      Exception - is thrown if something's gone wrong during mail send procedure
    • sendMessage

      void sendMessage(javax.mail.internet.MimeMessage message) throws Exception
      Sends mail message based on MimeMessage instance
      Parameters:
      message - - MimeMessage provides mail message related data (e.g. subject, content etc.)
      Throws:
      Exception - is thrown if something's gone wrong during mail send procedure
    • sendMessageInFuture

      Future<Boolean> sendMessageInFuture(String from, String to, String subject, String body)
      Asynchronous variant of sendMessage(String, String, String, String). Returns Future object, which allows to track mail sending result. Calling Future.get() for this object returns Boolean.TRUE if mail is sent successfully, throws ExecutionException if some exception occured during mail sending. Calling Throwable.getCause() for the thrown exception object provides the exception, which indeed occured during sending mail.
      Parameters:
      from - - String identificator of mail sender. For example 'test.sender@test.test'
      to - - String identificator of mail receiver. For example 'test.receiver@test.test'
      subject - - String subject of mail message
      body - - String contents of mail message
      Returns:
      Future object to watch the result of asynchronous calculation
    • sendMessageInFuture

      Future<Boolean> sendMessageInFuture(Message message)
      Asynchronous variant of sendMessage(Message). Returns Future object, which allows to track mail sending result. Calling Future.get() for this object returns Boolean.TRUE if mail is sent successfully, throws ExecutionException if some exception occured during mail sending. Calling Throwable.getCause() for the thrown exception object provides the exception, which indeed occured during sending mail.
      Parameters:
      message - - Message provides mail message related data (e.g. subject, content etc.)
      Returns:
      Future object to watch the result of asynchronous calculation
    • sendMessageInFuture

      Future<Boolean> sendMessageInFuture(javax.mail.internet.MimeMessage message)
      Asynchronous variant of sendMessage(MimeMessage). Returns Future object, which allows to track mail sending result. Calling Future.get() for this object returns Boolean.TRUE if mail is sent successfully, throws ExecutionException if some exception occured during mail sending. Calling Throwable.getCause() for the thrown exception object provides the exception, which indeed occured during sending mail.
      Parameters:
      message - - MimeMessage provides mail message related data (e.g. subject, content etc.)
      Returns:
      Future object to watch the result of asynchronous calculation