Class EmailUtil

java.lang.Object
net.sf.basedb.util.EmailUtil

public class EmailUtil extends Object
Utility class for email sending. Before use it must be initialized (this is done automatically when starting BASE). Configuration options in the base.config file are used.
  • mail.server.host: Host name of the outgoing smtp server. This must be set or email sending will be disabled.
  • mail.server.port: Port the outgoing smtp server is listening to. If not set the default port is used (25 for regular mail, 465 for SSL).
  • mail.server.ssl: If SSL is enabled or not.
  • mail.server.tsl: If TLS is enabled or not.
  • mail.from.email: Email address to use as the sender of outgoing emails. This must be set or email seding will be disabled.
  • mail.from.name: Name to use as the sender of outgoing emails. If not set a default name is created based on the host name of the BASE server.
Since:
2.16
Author:
Nicklas
Last modified
$Date: 2013-02-01 10:23:04 +0100 (fr, 01 feb 2013) $
  • Field Details

    • EMAIL_REGEXP

      public static final Pattern EMAIL_REGEXP
      This pattern can be used to find email addresses. The pattern will check that an @ symbol is present and that it is preceded with at least one character and followed by at least one subdomain and one topdomain. The pattern will allow any unicode letters, digits, underscore and hyphen in the address. It will not check that the domain or email address actually exists.
    • initialized

      private static boolean initialized
    • enabled

      private static boolean enabled
    • hostName

      private static String hostName
    • hostPort

      private static int hostPort
    • ssl

      private static boolean ssl
    • tls

      private static boolean tls
    • senderEmail

      private static String senderEmail
    • senderName

      private static String senderName
  • Constructor Details

    • EmailUtil

      public EmailUtil()
  • Method Details

    • init

      public static void init()
    • unload

      public static void unload()
      Unload all settings.
    • isEnabled

      public static boolean isEnabled()
      Check if email sending has been enabled for the server or not. Sending is disabled if the init() method hasn't been called, the server admin hasn't specified an outgoing smtp server or an outgoing sender email.
      Returns:
      TRUE if mails are enabled, FALSE otherwise
    • isEnabled

      public static boolean isEnabled(User user)
      Check if email sending is enabled for the given user. All of the following conditions must apply:
      Parameters:
      user - The user to check
    • isValidEmail

      public static boolean isValidEmail(String email)
      Checks if the given string looks like an email address. This is done by trying to match it against the EMAIL_REGEXP pattern.
      Parameters:
      email - The string to check
      Returns:
      TRUE or FALSE
      See Also:
    • createSimpleEmail

      public static org.apache.commons.mail.Email createSimpleEmail() throws org.apache.commons.mail.EmailException
      Create a simple text email. Host name, sender, etc. will be set according to the settigs from base.config. The caller need to set a 'To' address, 'Subject' and the actual message.
      Returns:
      An Email object, or null if mail sending is not enabled
      Throws:
      org.apache.commons.mail.EmailException - If there is something wrong with the setup