org.opengts.util
Class SendMail

java.lang.Object
  extended by org.opengts.util.SendMail

public class SendMail
extends java.lang.Object


Nested Class Summary
static class SendMail.Args
          A container for the arguments of an email
static class SendMail.Attachment
          A container for an email attachment
static class SendMail.SendMailException
          SendMailException
static class SendMail.SmtpProperties
           
 
Field Summary
static int _THREAD_CURRENT
           
static int _THREAD_DEBUG
           
static int _THREAD_NEW
           
static int _THREAD_NONE
           
static int _THREAD_POOL
           
static java.lang.String EXAMPLE_DOT_COM
           
static byte[] MAGIC_GIF_87a
           
static byte[] MAGIC_GIF_89a
           
static byte[] MAGIC_JPEG
           
static byte[] MAGIC_PNG
           
static java.lang.String SendMailArgs_className
           
static java.lang.String THREAD_CURRENT
           
static java.lang.String THREAD_DEBUG
           
static java.lang.String THREAD_NEW
           
static java.lang.String THREAD_NONE
           
static java.lang.String THREAD_POOL
           
static java.lang.String X_AlarmRule
           
static java.lang.String X_AssetId
           
static java.lang.String X_EventTime
           
static java.lang.String X_GPSLocation
           
static java.lang.String X_OriginatingIP
           
static java.lang.String X_OwnerId
           
static java.lang.String X_PageType
           
static java.lang.String X_Requestor
           
static java.lang.String X_StatusCode
           
 
Constructor Summary
SendMail()
           
 
Method Summary
static java.lang.String DefaultContentType(byte[] data)
          Returns the MIME contents type for the specified file contents
static java.lang.String getDefaultUserEmail(java.lang.String mainEmail)
          Returns the specified override "From" email address, if non-blank, otherwise the default configured "From" email address will be returned.
static java.lang.String getEMailAddress(java.lang.String addr)
          Filters and returns the base email address from the specified String.
For example, if the String "Jones<jones@example.com>" is passed to this method, then the value "jones@example.com" will be returned.
static boolean GetShowThreadModel()
          Sets the SendMail thread-model 'show' state (during debug mode)
static boolean IsBlankEmailAddress(java.lang.String email)
           
static boolean IsSendMailEnabled()
          Returns true if "SendMail" is enabled
static void main(java.lang.String[] argv)
          Command-line debug/testing entry point
static boolean SaveToOutbox(SendMail.Args args)
          Save specified SendMail Args to outbox
static boolean send(java.util.Properties headers, java.lang.String from, java.lang.String[] to, java.lang.String[] cc, java.lang.String[] bcc, java.lang.String subject, java.lang.String msgBody, SendMail.Attachment attach, SendMail.SmtpProperties smtpProps, boolean queRetry)
          Sends an email
static boolean send(java.lang.String from, java.lang.String to, java.lang.String subject, java.lang.String msgBody, SendMail.Attachment attach, SendMail.SmtpProperties smtpProps)
          Sends an email
static boolean send(java.lang.String from, java.lang.String to, java.lang.String subject, java.lang.String msgBody, SendMail.Attachment attach, SendMail.SmtpProperties smtpProps, boolean queRetry)
          Sends an email
static boolean send(java.lang.String from, java.lang.String to, java.lang.String subject, java.lang.String msgBody, SendMail.SmtpProperties smtpProps)
          Sends an email
static boolean send(java.lang.String from, java.lang.String to, java.lang.String subject, java.lang.String msgBody, SendMail.SmtpProperties smtpProps, boolean queRetry)
          Sends an email
static boolean send(java.lang.String from, java.lang.String to, java.lang.String cc, java.lang.String bcc, java.lang.String subject, java.lang.String msgBody, SendMail.Attachment attach, SendMail.SmtpProperties smtpProps)
          Sends an email
static boolean send(java.lang.String from, java.lang.String to, java.lang.String cc, java.lang.String bcc, java.lang.String subject, java.lang.String msgBody, SendMail.Attachment attach, SendMail.SmtpProperties smtpProps, boolean queRetry)
          Sends an email
static boolean sendSysadmin(java.lang.String subject, java.lang.String msgBody)
          Sends a system notification email to the defined system admin email address
static void SetShowThreadModel(boolean show)
          Returns true if the SendMail thread-model should be displayed when in debug mode.
static void SetSleepAfterEMailMS(long sleepMS)
          Sets the amount of time to sleep after sending an email.
Note: this must be used with caution, since it could cause a significant backlog if many emails are sent to the threadpool.
static void SetThreadModel(java.lang.String model)
          Sets the 'thread model' for email sent by this class.
The valid values are THREAD_CURRENT, THREAD_POOL, THREAD_NEW, or THREAD_DEBUG.
static void SetThreadModel(java.lang.String model, boolean show)
          Sets the 'thread model' for email sent by this class.
The valid values are THREAD_CURRENT, THREAD_POOL, THREAD_NEW, or THREAD_DEBUG.
static boolean validateAddress(java.lang.String addr)
          Validate the specified email address.
static boolean validateAddresses(java.lang.String addr)
          Validate the specified list of comma-separated email addresses.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SendMailArgs_className

public static final java.lang.String SendMailArgs_className
See Also:
Constant Field Values

EXAMPLE_DOT_COM

public static final java.lang.String EXAMPLE_DOT_COM
See Also:
Constant Field Values

X_OwnerId

public static final java.lang.String X_OwnerId
See Also:
Constant Field Values

X_AssetId

public static final java.lang.String X_AssetId
See Also:
Constant Field Values

X_PageType

public static final java.lang.String X_PageType
See Also:
Constant Field Values

X_Requestor

public static final java.lang.String X_Requestor
See Also:
Constant Field Values

X_OriginatingIP

public static final java.lang.String X_OriginatingIP
See Also:
Constant Field Values

X_EventTime

public static final java.lang.String X_EventTime
See Also:
Constant Field Values

X_StatusCode

public static final java.lang.String X_StatusCode
See Also:
Constant Field Values

X_AlarmRule

public static final java.lang.String X_AlarmRule
See Also:
Constant Field Values

X_GPSLocation

public static final java.lang.String X_GPSLocation
See Also:
Constant Field Values

MAGIC_GIF_87a

public static final byte[] MAGIC_GIF_87a

MAGIC_GIF_89a

public static final byte[] MAGIC_GIF_89a

MAGIC_JPEG

public static final byte[] MAGIC_JPEG

MAGIC_PNG

public static final byte[] MAGIC_PNG

THREAD_NONE

public static final java.lang.String THREAD_NONE
See Also:
Constant Field Values

_THREAD_NONE

public static final int _THREAD_NONE
See Also:
Constant Field Values

THREAD_CURRENT

public static final java.lang.String THREAD_CURRENT
See Also:
Constant Field Values

_THREAD_CURRENT

public static final int _THREAD_CURRENT
See Also:
Constant Field Values

THREAD_POOL

public static final java.lang.String THREAD_POOL
See Also:
Constant Field Values

_THREAD_POOL

public static final int _THREAD_POOL
See Also:
Constant Field Values

THREAD_NEW

public static final java.lang.String THREAD_NEW
See Also:
Constant Field Values

_THREAD_NEW

public static final int _THREAD_NEW
See Also:
Constant Field Values

THREAD_DEBUG

public static final java.lang.String THREAD_DEBUG
See Also:
Constant Field Values

_THREAD_DEBUG

public static final int _THREAD_DEBUG
See Also:
Constant Field Values
Constructor Detail

SendMail

public SendMail()
Method Detail

SetSleepAfterEMailMS

public static void SetSleepAfterEMailMS(long sleepMS)
Sets the amount of time to sleep after sending an email.
Note: this must be used with caution, since it could cause a significant backlog if many emails are sent to the threadpool.


IsSendMailEnabled

public static boolean IsSendMailEnabled()
Returns true if "SendMail" is enabled

Returns:
True if "SendMail" is enabled, otherwise false

IsBlankEmailAddress

public static boolean IsBlankEmailAddress(java.lang.String email)

SaveToOutbox

public static boolean SaveToOutbox(SendMail.Args args)
Save specified SendMail Args to outbox


SetShowThreadModel

public static void SetShowThreadModel(boolean show)
Returns true if the SendMail thread-model should be displayed when in debug mode.


GetShowThreadModel

public static boolean GetShowThreadModel()
Sets the SendMail thread-model 'show' state (during debug mode)


SetThreadModel

public static void SetThreadModel(java.lang.String model)
Sets the 'thread model' for email sent by this class.
The valid values are THREAD_CURRENT, THREAD_POOL, THREAD_NEW, or THREAD_DEBUG.

Parameters:
model - The specified thread model.

SetThreadModel

public static void SetThreadModel(java.lang.String model,
                                  boolean show)
Sets the 'thread model' for email sent by this class.
The valid values are THREAD_CURRENT, THREAD_POOL, THREAD_NEW, or THREAD_DEBUG.

Parameters:
model - The specified thread model.
show - True to display the thread model when sending an email (debug purposes only).

getDefaultUserEmail

public static java.lang.String getDefaultUserEmail(java.lang.String mainEmail)
Returns the specified override "From" email address, if non-blank, otherwise the default configured "From" email address will be returned.

Parameters:
mainEmail - The overriding email address to return if non-blank
Returns:
The SMTP user "From" email address.

sendSysadmin

public static boolean sendSysadmin(java.lang.String subject,
                                   java.lang.String msgBody)
Sends a system notification email to the defined system admin email address

Parameters:
subject - The email subject
msgBody - The email message body
Returns:
True if email is sent

send

public static boolean send(java.lang.String from,
                           java.lang.String to,
                           java.lang.String subject,
                           java.lang.String msgBody,
                           SendMail.SmtpProperties smtpProps)
Sends an email

Parameters:
from - The sender of the email
to - A comma-separated list of email recipients.
subject - The email subject.
msgBody - The email message body.
smtpProps - The custom SMTP properties
Returns:
True if email is queued/sent

send

public static boolean send(java.lang.String from,
                           java.lang.String to,
                           java.lang.String subject,
                           java.lang.String msgBody,
                           SendMail.SmtpProperties smtpProps,
                           boolean queRetry)
Sends an email

Parameters:
from - The sender of the email
to - A comma-separated list of email recipients.
subject - The email subject.
msgBody - The email message body.
smtpProps - The custom SMTP properties
queRetry - True to queue to outbox on connection/auth failure.
Returns:
True if email is queued/sent

send

public static boolean send(java.lang.String from,
                           java.lang.String to,
                           java.lang.String subject,
                           java.lang.String msgBody,
                           SendMail.Attachment attach,
                           SendMail.SmtpProperties smtpProps)
Sends an email

Parameters:
from - The sender of the email
to - A comma-separated list of email recipients.
subject - The email subject.
msgBody - The email message body.
attach - An email attachment
smtpProps - The custom SMTP properties
Returns:
True if email is queued/sent

send

public static boolean send(java.lang.String from,
                           java.lang.String to,
                           java.lang.String subject,
                           java.lang.String msgBody,
                           SendMail.Attachment attach,
                           SendMail.SmtpProperties smtpProps,
                           boolean queRetry)
Sends an email

Parameters:
from - The sender of the email
to - A comma-separated list of email recipients.
subject - The email subject.
msgBody - The email message body.
attach - An email attachment
smtpProps - The custom SMTP properties
queRetry - True to queue to outbox on connection/auth failure.
Returns:
True if email is queued/sent

send

public static boolean send(java.lang.String from,
                           java.lang.String to,
                           java.lang.String cc,
                           java.lang.String bcc,
                           java.lang.String subject,
                           java.lang.String msgBody,
                           SendMail.Attachment attach,
                           SendMail.SmtpProperties smtpProps)
Sends an email

Parameters:
from - The sender of the email
to - A comma-separated list of 'To:' email recipients.
cc - A comma-separated list of 'Cc:' email recipients.
bcc - A comma-separated list of 'Bcc:' email recipients.
subject - The email subject.
msgBody - The email message body.
attach - An email attachment
smtpProps - The custom SMTP properties
Returns:
True if email is queued/sent

send

public static boolean send(java.lang.String from,
                           java.lang.String to,
                           java.lang.String cc,
                           java.lang.String bcc,
                           java.lang.String subject,
                           java.lang.String msgBody,
                           SendMail.Attachment attach,
                           SendMail.SmtpProperties smtpProps,
                           boolean queRetry)
Sends an email

Parameters:
from - The sender of the email
to - A comma-separated list of 'To:' email recipients.
cc - A comma-separated list of 'Cc:' email recipients.
bcc - A comma-separated list of 'Bcc:' email recipients.
subject - The email subject.
msgBody - The email message body.
attach - An email attachment
smtpProps - The custom SMTP properties
queRetry - True to queue to outbox on connection/auth failure.
Returns:
True if email is queued/sent

send

public static boolean send(java.util.Properties headers,
                           java.lang.String from,
                           java.lang.String[] to,
                           java.lang.String[] cc,
                           java.lang.String[] bcc,
                           java.lang.String subject,
                           java.lang.String msgBody,
                           SendMail.Attachment attach,
                           SendMail.SmtpProperties smtpProps,
                           boolean queRetry)
Sends an email

Parameters:
from - The sender of the email
to - An array of 'To:' email recipients.
cc - An array of 'Cc:' email recipients.
bcc - An array of 'Bcc:' email recipients.
subject - The email subject.
msgBody - The email message body.
attach - An email attachment
smtpProps - The custom SMTP properties
queRetry - An email attachment
Returns:
True

DefaultContentType

public static java.lang.String DefaultContentType(byte[] data)
Returns the MIME contents type for the specified file contents

Parameters:
data - The file contents
Returns:
The MIME content type

validateAddresses

public static boolean validateAddresses(java.lang.String addr)
Validate the specified list of comma-separated email addresses.

Parameters:
addr - A comma-separated list of email addresses
Returns:
True if all addresses in the list are valid, false otherwise

validateAddress

public static boolean validateAddress(java.lang.String addr)
Validate the specified email address.

Parameters:
addr - The email address to validate.
Returns:
True if the specified email address is valid, false otherwise

getEMailAddress

public static java.lang.String getEMailAddress(java.lang.String addr)
Filters and returns the base email address from the specified String.
For example, if the String "Jones<jones@example.com>" is passed to this method, then the value "jones@example.com" will be returned.

Parameters:
addr - The email address to filter.
Returns:
The filtered email address, or null if the specified email address is invalid.

main

public static void main(java.lang.String[] argv)
Command-line debug/testing entry point

Parameters:
argv - The command-line arguments