Class SFSPostOffice

  • All Implemented Interfaces:
    com.smartfoxserver.bitswarm.service.IService, IMailerService

    public class SFSPostOffice
    extends java.lang.Object
    implements IMailerService
    SFSPostOffice is the default implementation of the IMailerService which is provided by the SmartFoxServer class- This service provides a simple mailing service capable of sending text and html emails via a configured SMTP service. SMPT ports supported are 25, 587 and 465 (SSL). The service can be configured via the SFS2X AdminTool GUI.

    You can obtain access to the service via the following line of code:

     SmartFoxServer.getInstance().getMailService();
     

    In order to ensure proper communication between SmartFoxServer and the SMTP server we make sure to double check your hosting firewall settings and make sure traffic is allowed on the chosen port.

    There are three modalities for sending an email:

    • No notice send: simply send the email in "hyperspace"
    • Callback send: you provide a callback class that will be invoked once the email has been delivered. The callback notifies either the success of the operation or an exception with the details of what went wrong.
    • Delayed send: you can specify a time in the future when the email should be sent
    NOTE: as with any other email system there is no 100% guarantee of delivery even when the callback reports a success. The success notification simply indicates that SFS2X was able to contact the SMTP server and deliver the message to it. The email might then be filtered by an anti-spam system, or get refused because the recipient inbox is full etc...
    • Constructor Summary

      Constructors 
      Constructor Description
      SFSPostOffice()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy​(java.lang.Object o)
      Destroy service
      com.smartfoxserver.v2.config.MailerSettings getConfiguration()
      Obtain the configuration settings of the service
      java.lang.String getName()
      Get the service name
      void handleMessage​(java.lang.Object message)
      Send message to service
      void init​(java.lang.Object o)
      Initialize service
      void sendMail​(Email email)
      Sends the email to the recipient, or list of recipients, specified in the Email argument.
      void sendMail​(Email email, IMailerCallbackHandler callBack)
      Sends the email to the recipient, or list of recipients, specified in the Email argument and get an asynchronous event when the email is delivered.
      void sendMail​(Email email, IMailerCallbackHandler callBack, int delaySeconds)
      Sends an email in the future.
      void setName​(java.lang.String name)
      Set the service name
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SFSPostOffice

        public SFSPostOffice()
    • Method Detail

      • init

        public void init​(java.lang.Object o)
        Description copied from interface: com.smartfoxserver.bitswarm.service.IService
        Initialize service
        Specified by:
        init in interface com.smartfoxserver.bitswarm.service.IService
        Parameters:
        o - custom parameters
      • destroy

        public void destroy​(java.lang.Object o)
        Description copied from interface: com.smartfoxserver.bitswarm.service.IService
        Destroy service
        Specified by:
        destroy in interface com.smartfoxserver.bitswarm.service.IService
        Parameters:
        o - custom parameters
      • getName

        public java.lang.String getName()
        Description copied from interface: com.smartfoxserver.bitswarm.service.IService
        Get the service name
        Specified by:
        getName in interface com.smartfoxserver.bitswarm.service.IService
        Returns:
        the service name
      • getConfiguration

        public com.smartfoxserver.v2.config.MailerSettings getConfiguration()
        Obtain the configuration settings of the service
        Specified by:
        getConfiguration in interface IMailerService
        Returns:
        the configuration settings of the service
      • sendMail

        public void sendMail​(Email email,
                             IMailerCallbackHandler callBack)
                      throws javax.mail.MessagingException
        Sends the email to the recipient, or list of recipients, specified in the Email argument and get an asynchronous event when the email is delivered.

        In order to send an email to multiple recipients the Email toAddress should contain comma-separated (and valid) email addresses. Don't use any blank spaces in the separation of each address.

        NOTE: Sending emails requires to add the mailapi.jar (found under SFS2X/lib/) to your project's libraries.

        Specified by:
        sendMail in interface IMailerService
        Parameters:
        email - the email to send
        callBack - the callback handler, if null no event will be fired
        Throws:
        javax.mail.MessagingException - an error might be caused by malformed email addresses either in the TO or FROM fields
        See Also:
        SFSEmail
      • sendMail

        public void sendMail​(Email email)
                      throws javax.mail.MessagingException
        Sends the email to the recipient, or list of recipients, specified in the Email argument.

        In order to send an email to multiple recipients the Email toAddress should contain comma-separated (and valid) email addresses. Don't use any blank spaces in the separation of each address.

        NOTE: Sending emails requires to add the mailapi.jar (found under SFS2X/lib/) to your project's libraries.

        Specified by:
        sendMail in interface IMailerService
        Parameters:
        email - the email to send
        Throws:
        javax.mail.MessagingException - an error might be caused by malformed email addresses either in the TO or FROM fields
        See Also:
        SFSEmail
      • sendMail

        public void sendMail​(Email email,
                             IMailerCallbackHandler callBack,
                             int delaySeconds)
                      throws javax.mail.MessagingException
        Sends an email in the future. The email can be sent to one recipient or a list of recipients specified in the Email argument. If a callback handler is provided the system will fire an asynchronous event when the email is delivered.

        In order to send an email to multiple recipients the Email toAddress should contain comma-separated (and valid) email addresses. Don't use any blank spaces in the separation of each address.

        NOTE: Sending emails requires to add the mailapi.jar (found under SFS2X/lib/) to your project's libraries.

        Specified by:
        sendMail in interface IMailerService
        Parameters:
        email - the email to send
        callBack - the callback handler, if null no event will be fired
        delaySeconds - the amount of seconds to wait before sendint the mail
        Throws:
        javax.mail.MessagingException - an error might be caused by malformed email addresses either in the TO or FROM fields
        See Also:
        SFSEmail
      • handleMessage

        public void handleMessage​(java.lang.Object message)
        Description copied from interface: com.smartfoxserver.bitswarm.service.IService
        Send message to service
        Specified by:
        handleMessage in interface com.smartfoxserver.bitswarm.service.IService
        Parameters:
        message - the message
      • setName

        public void setName​(java.lang.String name)
        Description copied from interface: com.smartfoxserver.bitswarm.service.IService
        Set the service name
        Specified by:
        setName in interface com.smartfoxserver.bitswarm.service.IService
        Parameters:
        name - the service name