Class GreenMailBean

  • All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean

    public class GreenMailBean
    extends Object
    implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.BeanNameAware
    Spring bean for GreenMail server.

    By default,

    • SMTP, POP3 services are activated
    • autostart is enabled
    • port offset is 3000
    Author:
    Marcel May (mm)
    • Field Detail

      • log

        protected final org.slf4j.Logger log
        New logger.
    • Constructor Detail

      • GreenMailBean

        public GreenMailBean()
    • Method Detail

      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws Exception
        Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

        This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        Exception - in the event of misconfiguration (such as failure to set an essential property) or if initialization fails.
      • start

        public void start()
        Starts the server.
      • stop

        public void stop()
        Stops the server.
      • getReceivedMessages

        public jakarta.mail.internet.MimeMessage[] getReceivedMessages()
        Gets the currently received messages.
        Returns:
        the available messages.
      • destroy

        public void destroy()
                     throws Exception
        Invoked by a BeanFactory on destruction of a singleton.
        Specified by:
        destroy in interface org.springframework.beans.factory.DisposableBean
        Throws:
        Exception - in case of shutdown errors. Exceptions will get logged but not rethrown to allow other beans to release their resources too.
      • setAutostart

        public void setAutostart​(boolean theAutostart)
        Sets the autostart flag.
        Parameters:
        theAutostart - the flag.
      • isAutostart

        public boolean isAutostart()
        Getter for property 'autostart'.
        Returns:
        Value for property 'autostart'.
      • setSmtpProtocol

        public void setSmtpProtocol​(boolean theSmtpProtocoll)
        Setter for property 'smtpProtocol'.
        Parameters:
        theSmtpProtocoll - Value to set for property 'smtpProtocol'.
      • isSmtpProtocol

        public boolean isSmtpProtocol()
        Getter for property 'smtpProtocol'.
        Returns:
        Value for property 'smtpProtocol'.
      • setSmtpsProtocol

        public void setSmtpsProtocol​(boolean theSmtpsProtocoll)
        Setter for property 'smtpsProtocol'.
        Parameters:
        theSmtpsProtocoll - Value to set for property 'smtpsProtocol'.
      • isSmtpsProtocol

        public boolean isSmtpsProtocol()
        Getter for property 'smtpsProtocol'.
        Returns:
        Value for property 'smtpsProtocol'.
      • setPop3Protocol

        public void setPop3Protocol​(boolean thePop3Protocoll)
        Setter for property 'pop3Protocol'.
        Parameters:
        thePop3Protocoll - Value to set for property 'pop3Protocol'.
      • isPop3Protocol

        public boolean isPop3Protocol()
        Getter for property 'pop3Protocol'.
        Returns:
        Value for property 'pop3Protocol'.
      • setPop3sProtocol

        public void setPop3sProtocol​(boolean thePop3sProtocoll)
        Setter for property 'pop3sProtocol'.
        Parameters:
        thePop3sProtocoll - Value to set for property 'pop3sProtocol'.
      • isPop3sProtocol

        public boolean isPop3sProtocol()
        Getter for property 'pop3sProtocol'.
        Returns:
        Value for property 'pop3sProtocol'.
      • setImapProtocol

        public void setImapProtocol​(boolean theImapProtocoll)
        Setter for property 'imapProtocol'.
        Parameters:
        theImapProtocoll - Value to set for property 'imapProtocol'.
      • isImapProtocol

        public boolean isImapProtocol()
        Getter for property 'imapProtocol'.
        Returns:
        Value for property 'imapProtocol'.
      • setImapsProtocol

        public void setImapsProtocol​(boolean theImapsProtocoll)
        Setter for property 'imapsProtocol'.
        Parameters:
        theImapsProtocoll - Value to set for property 'imapsProtocol'.
      • isImapsProtocol

        public boolean isImapsProtocol()
        Getter for property 'imapsProtocol'.
        Returns:
        Value for property 'imapsProtocol'.
      • setHostname

        public void setHostname​(String pHostname)
        Setter for property 'hostname'.
        Parameters:
        pHostname - Value to set for property 'hostname'.
      • getHostname

        public String getHostname()
        Getter for property 'hostname'.
        Returns:
        Value for property 'hostname'.
      • setPortOffset

        public void setPortOffset​(int pPortOffset)
        Setter for property 'portOffset'.
        Parameters:
        pPortOffset - Value to set for property 'portOffset'.
      • getPortOffset

        public int getPortOffset()
        Getter for property 'portOffset'.
        Returns:
        Value for property 'portOffset'.
      • getUserManager

        public UserManager getUserManager()
        Convenience method for directly accessing UserManager.
        Returns:
        the user manager.
      • setUsers

        public void setUsers​(List<String> theUsers)
        Setter for property 'users'.
        Parameters:
        theUsers - Value to set for property 'users'.
      • getUsers

        public List<String> getUsers()
        Getter for property 'users'.
        Returns:
        Value for property 'users'.
      • isStarted

        public boolean isStarted()
        Getter for property 'started'.
        Returns:
        Value for property 'started'.
      • getGreenMail

        public GreenMail getGreenMail()
        Getter for property 'greenMail'.
        Returns:
        Value for property 'greenMail'.
      • sendEmail

        public void sendEmail​(String theTo,
                              String theFrom,
                              String theSubject,
                              String theContent)
        Sends a mail message to the GreenMail server.

        Note: SMTP or SMTPS must be configured.

        Parameters:
        theTo - the TO field.
        theFrom - the FROMfield.
        theSubject - the subject.
        theContent - the message content.
      • setBeanName

        public void setBeanName​(String pName)
        Specified by:
        setBeanName in interface org.springframework.beans.factory.BeanNameAware
      • getServerStartupTimeout

        public long getServerStartupTimeout()
        Timeout to wait for server startup in millis
        Returns:
        Value for property 'serverStartupTimeout'
      • setServerStartupTimeout

        public void setServerStartupTimeout​(long serverStartupTimeout)