Package net.sf.basedb.util
Class EmailUtil
java.lang.Object
net.sf.basedb.util.EmailUtil
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 Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.commons.mail.Email
Create a simple text email.static void
init()
static boolean
Check if email sending has been enabled for the server or not.static boolean
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.
-
Field Details
-
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
-
hostPort
private static int hostPort -
ssl
private static boolean ssl -
tls
private static boolean tls -
senderEmail
-
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 theinit()
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
Check if email sending is enabled for the given user. All of the following conditions must apply:- The server must be configured for sending emails (see
isEnabled()
). - The user must have selected to have emails (
User.getSendMessagesAsEmail()
). - The user must have a valid email address.
- Parameters:
user
- The user to check
- The server must be configured for sending emails (see
-
isValidEmail
Checks if the given string looks like an email address. This is done by trying to match it against theEMAIL_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.EmailExceptionCreate 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
-