2.17.2: 2011-06-17

net.sf.basedb.util
Class EmailUtil

java.lang.Object
  extended by 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.

Since:
2.16
Author:
Nicklas
Last modified
$Date: 2010-10-07 08:48:16 +0200 (Thu, 07 Oct 2010) $

Field Summary
static Pattern EMAIL_REGEXP
          This pattern can be used to find email addresses.
private static boolean enabled
           
private static String hostName
           
private static int hostPort
           
private static boolean initialized
           
private static String senderEmail
           
private static String senderName
           
private static boolean ssl
           
private static boolean tls
           
 
Constructor Summary
EmailUtil()
           
 
Method Summary
static org.apache.commons.mail.Email createSimpleEmail()
          Create a simple text email.
static void init()
           
static boolean isEnabled()
          Check if email sending has been enabled for the server or not.
static boolean isEnabled(User user)
          Check if email sending is enabled for the given user.
static boolean isValidEmail(String email)
          Checks if the given string looks like an email address.
static void unload()
          Unload all settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 Detail

EmailUtil

public EmailUtil()
Method Detail

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:
EMAIL_REGEXP

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

2.17.2: 2011-06-17