com.email
Class EmailCarrier

java.lang.Object
  |
  +--com.email.EmailCarrier

public final class EmailCarrier
extends java.lang.Object

Author : Sameer Bagade
Version : 1.0


Field Summary
static int MESSAGE_TYPE_HTML
          int value to set content type for html format
static int MESSAGE_TYPE_TEXT
          int value to set content type for text format
static int RECIPIENT_TYPE_BCC
          int value to represent recipient type for BCC
static int RECIPIENT_TYPE_CC
          int value to represent recipient type for CC
static int RECIPIENT_TYPE_TO
          int value to represent recipient type for TO
 
Constructor Summary
EmailCarrier()
          Creates new EmailCarrier
 
Method Summary
 java.util.Hashtable getAttachments()
          Gets all attachments
 java.util.ArrayList getBCCList()
          Get the recipient list of email for BCC.
 java.util.ArrayList getCCList()
          Get the recipient list of email for CC.
 java.lang.String getFrom()
          Get email address of Sender.
 java.lang.String getMsg()
          Get the email message.
 java.lang.String getSmtpHost()
          Get the SMTP mail server address.
 java.lang.String getSubject()
          Get the email subject.
 java.util.ArrayList getToList()
          Get the recipient list of email for TO.
 void insertAttachments(java.util.Hashtable pAttachments, java.lang.String pMsg, int pMsgType)
          Inserts attachments.
 void insertAttachments(java.lang.String[] pAttachments, java.lang.String pMsg, int pMsgType)
          Inserts attachments.
 void insertAttachments(java.lang.String pAttachments, java.lang.String pMsg, int pMsgType)
          Inserts attachments.
static boolean isValid(java.util.Hashtable obj)
          checks the validity of an String array object
static boolean isValid(java.lang.String[] obj)
          checks the validity of an String array object
 boolean isValidEmail(java.lang.String str)
          Validates an email addres
static java.lang.String makeValid(java.lang.String obj)
          checks the validity of an String object and converts to empty String if its null
static boolean sendEmail(java.lang.String host, java.lang.String pFrom, java.lang.String[] pTo, java.lang.String[] pCC, java.lang.String[] pBCC, java.lang.String pSub, java.lang.String pMsg, java.util.Hashtable pAttachment, int pMsgType)
          Sends an Email to specified recipients in an array with many attachments
static boolean sendEmail(java.lang.String host, java.lang.String pFrom, java.lang.String pTo, java.lang.String pCC, java.lang.String pBCC, java.lang.String pSub, java.lang.String pMsg, java.util.Hashtable pAttachment, int pMsgType)
          Sends an Email to specified recipients with many attachments
static boolean sendEmail(java.lang.String host, java.lang.String pFrom, java.lang.String pTo, java.lang.String pCC, java.lang.String pBCC, java.lang.String pSub, java.lang.String pMsg, int pMsgType)
          Sends an Email to specified recipients with no attachments
static boolean sendEmail(java.lang.String host, java.lang.String pFrom, java.lang.String pTo, java.lang.String pCC, java.lang.String pBCC, java.lang.String pSub, java.lang.String pMsg, java.lang.String pAttachment, java.lang.String pDisplayName, int pMsgType)
          Sends an Email to specified recipients in an array with one attachment
 boolean sendEmailCarrier()
          processes and transports emails.
 void setAttachments(java.util.Hashtable pAttachments)
          Sets the attachments
 void setBCCList(java.util.ArrayList pBCCList)
          Set the recipient list of email for BCC.
 void setCCList(java.util.ArrayList pCCList)
          Set the recipient list of email for CC.
 void setContent(java.lang.String pMsg, int pMsgType)
          Sets the message and content type for text email without attachment
 void setFrom(java.lang.String pFrom)
          Set email address of Sender.
 void setMessageSubject(java.lang.String pMessageSubject)
          Set the email subject
 void setMessageText(java.lang.String pMessageText)
          Set the email message text
 void setRecipients(int recipient_type, java.lang.String recipient_addr)
          Sets the recipient to the list according to the recipient_type
 void setRecipients(int recipient_type, java.lang.String[] recipient_addr)
          Sets the recipient to the list according to the recipient_type
 void setSmtpHost(java.lang.String pHost)
          Set the SMTP mail server address.
 void setToList(java.util.ArrayList pToList)
          Set the recipient list of email for TO.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RECIPIENT_TYPE_TO

public static final int RECIPIENT_TYPE_TO
int value to represent recipient type for TO

RECIPIENT_TYPE_CC

public static final int RECIPIENT_TYPE_CC
int value to represent recipient type for CC

RECIPIENT_TYPE_BCC

public static final int RECIPIENT_TYPE_BCC
int value to represent recipient type for BCC

MESSAGE_TYPE_TEXT

public static final int MESSAGE_TYPE_TEXT
int value to set content type for text format

MESSAGE_TYPE_HTML

public static final int MESSAGE_TYPE_HTML
int value to set content type for html format
Constructor Detail

EmailCarrier

public EmailCarrier()
Creates new EmailCarrier
Method Detail

sendEmail

public static boolean sendEmail(java.lang.String host,
                                java.lang.String pFrom,
                                java.lang.String pTo,
                                java.lang.String pCC,
                                java.lang.String pBCC,
                                java.lang.String pSub,
                                java.lang.String pMsg,
                                int pMsgType)
                         throws java.lang.Exception
Sends an Email to specified recipients with no attachments
Parameters:
host - SMTP Mail Server Address
pFrom - An email address of a sender
pTo - A String containing email addresses of recipients in TO List
pCC - A String containing email addresses of recipients in CC List
pBCC - A String containing email addresses of recipients in BCC List
pSub - Subject of an email
pMsg - Text message to be send with an email
pMsgType - int to set the message type MESSAGE_TYPE_TEXT for text messages MESSAGE_TYPE_HTML for TML messages
Returns:
true if email has been sent succesfully, false otherwise
Throws:
java.lang.Exception - java.lang.Exception

sendEmail

public static boolean sendEmail(java.lang.String host,
                                java.lang.String pFrom,
                                java.lang.String pTo,
                                java.lang.String pCC,
                                java.lang.String pBCC,
                                java.lang.String pSub,
                                java.lang.String pMsg,
                                java.lang.String pAttachment,
                                java.lang.String pDisplayName,
                                int pMsgType)
                         throws java.lang.Exception
Sends an Email to specified recipients in an array with one attachment
Parameters:
host - SMTP Mail Server Address
pFrom - An email address of a sender
pTo - Email address of recipients in TO List
pCC - Email address of recipients in CC List
pBCC - Email addresses of recipients in BCC List
pSub - Subject of an email
pMsg - Text message to be send with an email
pAttachment - Path and file name to be attached
pDisplayName - File name to show attachment in email
pMsgType - int to set the message type MESSAGE_TYPE_TEXT for text messages MESSAGE_TYPE_HTML for TML messages
Returns:
true if email has been sent succesfully, false otherwise
Throws:
java.lang.Exception - java.lang.Exception

sendEmail

public static boolean sendEmail(java.lang.String host,
                                java.lang.String pFrom,
                                java.lang.String pTo,
                                java.lang.String pCC,
                                java.lang.String pBCC,
                                java.lang.String pSub,
                                java.lang.String pMsg,
                                java.util.Hashtable pAttachment,
                                int pMsgType)
                         throws java.lang.Exception
Sends an Email to specified recipients with many attachments
Parameters:
host - SMTP Mail Server Address
pFrom - An email address of a sender
pTo - A String containing email addresses of recipients in TO List
pCC - A String containing email addresses of recipients in CC List
pBCC - A String containing email addresses of recipients in BCC List
pSub - Subject of an email
pMsg - Text message to be send with an email
pAttachment - A Hashtable of key value pair of display file name and full path and file name of attachment
pMsgType - int to set the message type MESSAGE_TYPE_TEXT for text messages MESSAGE_TYPE_HTML for TML messages
Returns:
true if email has been sent succesfully, false otherwise
Throws:
java.lang.Exception - java.lang.Exception

sendEmail

public static boolean sendEmail(java.lang.String host,
                                java.lang.String pFrom,
                                java.lang.String[] pTo,
                                java.lang.String[] pCC,
                                java.lang.String[] pBCC,
                                java.lang.String pSub,
                                java.lang.String pMsg,
                                java.util.Hashtable pAttachment,
                                int pMsgType)
                         throws java.lang.Exception
Sends an Email to specified recipients in an array with many attachments
Parameters:
host - SMTP Mail Server Address
pFrom - An email address of a sender
pTo - An array of String containing email addresses of recipients in TO List
pCC - An array of String containing email addresses of recipients in CC List
pBCC - An array of String containing email addresses of recipients in BCC List
pSub - Subject of an email
pMsg - Text message to be send with an email
pAttachment - A Hashtable of key value pair of display file name and full path and file name of attachment
pMsgType - int to set the message type MESSAGE_TYPE_TEXT for text messages MESSAGE_TYPE_HTML for TML messages
Returns:
true if email has been sent succesfully, false otherwise
Throws:
java.lang.Exception - java.lang.Exception

setContent

public void setContent(java.lang.String pMsg,
                       int pMsgType)
                throws java.lang.Exception
Sets the message and content type for text email without attachment
Parameters:
pMsg - String message to set
pMsgType - int to set message type
Throws:
java.lang.Exception - java.lang.Exception

getAttachments

public java.util.Hashtable getAttachments()
Gets all attachments
Returns:
key value pair of display file name and full file path with name

setAttachments

public void setAttachments(java.util.Hashtable pAttachments)
Sets the attachments
Parameters:
pAttachments - Hashtable having key value pair of display file name and full file path with name

isValidEmail

public boolean isValidEmail(java.lang.String str)
Validates an email addres
Parameters:
str - An email address to be validated
Returns:
boolean returns true if email address is valid or false if its invalid

isValid

public static boolean isValid(java.lang.String[] obj)
checks the validity of an String array object
Parameters:
obj - Array of String to be validated
Returns:
false if array is null or empty, true otherwise

makeValid

public static java.lang.String makeValid(java.lang.String obj)
checks the validity of an String object and converts to empty String if its null
Parameters:
obj - String to be validated
Returns:
empty String if object is null, same String otherwise

isValid

public static boolean isValid(java.util.Hashtable obj)
checks the validity of an String array object
Parameters:
obj - Hashtable to be validated
Returns:
false if Hashtable is null or empty, true otherwise

getSmtpHost

public java.lang.String getSmtpHost()
Get the SMTP mail server address.
Returns:
returns the SMTP mail server address

setSmtpHost

public void setSmtpHost(java.lang.String pHost)
Set the SMTP mail server address.
Parameters:
pHost - the SMTP mail server address

getFrom

public java.lang.String getFrom()
Get email address of Sender.
Returns:
returns String email address of sender

setFrom

public void setFrom(java.lang.String pFrom)
Set email address of Sender.
Parameters:
pFrom - email address of sender

getMsg

public java.lang.String getMsg()
Get the email message.
Returns:
String value of email message

getSubject

public java.lang.String getSubject()
Get the email subject.
Returns:
String value of email subject

getToList

public java.util.ArrayList getToList()
Get the recipient list of email for TO.
Returns:
ArrayList of email addresses in TO list

setToList

public void setToList(java.util.ArrayList pToList)
Set the recipient list of email for TO.
Parameters:
pToList - ArrayList of email addresses to be set in TO list

getCCList

public java.util.ArrayList getCCList()
Get the recipient list of email for CC.
Returns:
ArrayList of email addresses in CC list

setCCList

public void setCCList(java.util.ArrayList pCCList)
Set the recipient list of email for CC.
Parameters:
pCCList - ArrayList of email addresses to be set in CC list

getBCCList

public java.util.ArrayList getBCCList()
Get the recipient list of email for BCC.
Returns:
ArrayList of email addresses in BCC list

setBCCList

public void setBCCList(java.util.ArrayList pBCCList)
Set the recipient list of email for BCC.
Parameters:
pBCCList - ArrayList of email addresses to be set in BCC list

setRecipients

public void setRecipients(int recipient_type,
                          java.lang.String recipient_addr)
                   throws javax.mail.internet.AddressException,
                          java.lang.Exception
Sets the recipient to the list according to the recipient_type
Parameters:
recipient_type - RECIPIENT_TYPE_TO for TO RECIPIENT_TYPE_CC for CC RECIPIENT_TYPE_BCC for BCC
recipient_addr - recipient email address
Throws:
javax.mail.internet.AddressException - javax.mail.internet.AddressException The exception thrown when a wrongly formatted address is encountered.
java.lang.Exception - java.lang.Exception

setRecipients

public void setRecipients(int recipient_type,
                          java.lang.String[] recipient_addr)
                   throws javax.mail.internet.AddressException,
                          java.lang.Exception
Sets the recipient to the list according to the recipient_type
Parameters:
recipient_type - RECIPIENT_TYPE_TO for TO RECIPIENT_TYPE_CC for CC RECIPIENT_TYPE_BCC for BCC
recipient_addr - array of String containing email addresses of recipient
Throws:
javax.mail.internet.AddressException - javax.mail.internet.AddressException The exception thrown when a wrongly formatted address is encountered.
java.lang.Exception - java.lang.Exception

setMessageText

public void setMessageText(java.lang.String pMessageText)
                    throws javax.mail.MessagingException
Set the email message text
Parameters:
pMessageText - Message text for email
Throws:
javax.mail.MessagingException - The base class for all exceptions thrown by the Messaging classes

setMessageSubject

public void setMessageSubject(java.lang.String pMessageSubject)
                       throws javax.mail.MessagingException
Set the email subject
Parameters:
pMessageSubject - Subject of email
Throws:
javax.mail.MessagingException - javax.mail.MessagingException The base class for all exceptions thrown by the Messaging classes

insertAttachments

public void insertAttachments(java.lang.String[] pAttachments,
                              java.lang.String pMsg,
                              int pMsgType)
                       throws java.lang.Exception
Inserts attachments.
Parameters:
pAttachments - An array of String having attachment path and file name
pMsgType - int to set the message type MESSAGE_TYPE_TEXT for text messages MESSAGE_TYPE_HTML for TML messages
pMsg - Text message to be send with an email
Throws:
java.lang.Exception - java.lang.Exception

insertAttachments

public void insertAttachments(java.util.Hashtable pAttachments,
                              java.lang.String pMsg,
                              int pMsgType)
                       throws java.lang.Exception
Inserts attachments.
Parameters:
pAttachments - An array of String having attachment path and file name
pMsgType - int to set the message type MESSAGE_TYPE_TEXT for text messages MESSAGE_TYPE_HTML for TML messages
pMsg - Text message to be send with an email
Throws:
java.lang.Exception - java.lang.Exception

insertAttachments

public void insertAttachments(java.lang.String pAttachments,
                              java.lang.String pMsg,
                              int pMsgType)
                       throws java.lang.Exception
Inserts attachments.
Parameters:
pAttachments - A String contating attachment path and file name
pMsgType - int to set the message type MESSAGE_TYPE_TEXT for text messages MESSAGE_TYPE_HTML for TML messages
pMsg - Text message to be send with an email
Throws:
java.lang.Exception - java.lang.Exception

sendEmailCarrier

public boolean sendEmailCarrier()
                         throws java.lang.Exception
processes and transports emails.
Returns:
true if email has been sent succesfully, false otherwise
Throws:
java.lang.Exception - java.lang.Exception