Enhydra-Oyster 2.1-7 API

org.enhydra.oyster.smime
Class BaseSMIMEObject

java.lang.Object
  extended byorg.enhydra.oyster.smime.BaseSMIMEObject
All Implemented Interfaces:
KeyStoreConstants
Direct Known Subclasses:
BaseSignedSMIMEObject, EnvelopedSMIME, PureMIME

public class BaseSMIMEObject
extends java.lang.Object
implements KeyStoreConstants

This class is used as super class for all four email types with SMIME cryptography capabilities (Enveloped, Signed Signed and Enveloped and Enveloped and Signed). It contains the common methods for all this types. Also, this class is used as a super class for class PureMIME which can be used in creation and sending of pure MIME messages withouth cryptography posibilities.


Field Summary
protected  java.util.Vector bodyPartArray
          Storage for MIME bodyparts
protected  java.util.Vector certArray
          Storage for .cer files coresponding to appropriate enveloping session
protected  java.lang.String charsetEnc
          Character set definition.
protected  boolean contentPresence
          Indicator of the email message content part presence (it can be plain text or html content).
protected  boolean externalMessagePresence
          Indicator of the external MimeMessage object presence.
protected  boolean indicatorTo
          Indication that at least one recipient must be TO (others may be CC or BCC)
protected  javax.mail.internet.MimeMessage message
          Container for MIME message
 
Fields inherited from interface org.enhydra.oyster.crypto.consts.KeyStoreConstants
BKS, JKS, PKCS12, UBER
 
Constructor Summary
protected BaseSMIMEObject()
          Simple constructor.
protected BaseSMIMEObject(javax.mail.internet.MimeMessage mimeMessage)
          Construction of message with external prepared MimeMessage object.
protected BaseSMIMEObject(java.lang.String smtpHost, java.lang.String fromAddress, java.lang.String subject, java.lang.String charset)
          Initializes the JavaMail session for SMTP and the MimeMessage object for message which will be sent.
protected BaseSMIMEObject(java.lang.String smtpHost, java.lang.String fromAddress, java.lang.String subject, java.lang.String content, java.lang.String charset)
          Initializes the JavaMail session for SMTP and the MimeMessage object for message which will be sent.
 
Method Summary
 void addAttachment(java.io.File file)
          Adds file as attachment to email message.
 void addAttachment(java.io.File file, java.lang.String encoding)
          Adds file as attachment to email message with given value for prefered Content-Transfer-Encoding argument.
 void addAttachment(java.io.InputStream data, java.lang.String fileName)
          Adds data from InputStream as attachment to email message.
 void addAttachment(java.io.InputStream data, java.lang.String fileName, java.lang.String encoding)
          Adds data from InputStream as attachment to email message with given value for prefered Content-Transfer-Encoding argument.
 void addAttachment(java.lang.String fileName)
          Adds file as attachment to email message.
 void addAttachment(java.lang.String fileName, java.lang.String encoding)
          Adds file as attachment to email message with given value for prefered Content-Transfer-Encoding argument.
protected  void addRecipient(java.lang.String recipientAddress, java.lang.String type, java.security.KeyStore kStore, java.lang.String alias)
          Adds recipient address, type and recipient's certificate via KeyStore object and apropriate alias.
protected  void addRecipient(java.lang.String recipientAddress, java.lang.String type, java.lang.String cerFileName)
          Adds recipient address, type and .cer file of email recipient to encrypted message.
protected  void addRecipient(java.lang.String recipientAddress, java.lang.String type, java.lang.String ksPath, java.lang.String ksType, java.lang.String password, java.lang.String alias)
          Adds recipient address, type and recipient's certificate via path to the KeyStore file, KeyStore type, password and apropriate alias.
 javax.mail.internet.MimeMessage getMimeMessage()
          Returns MimeMessage.
 void initMimeMessage(java.lang.String smtpHost, java.lang.String fromAddress, java.lang.String subject, java.lang.String content, java.lang.String charset)
          Initializes the JavaMail session for SMTP and the MimeMessage object for message which will be sent.
 void reset()
          Resets all attributes in BaseSMIMEObject to their initial values.
 void send()
          Sends S/MIME message to SMTP host.
 void setCharsetEncoding(java.lang.String charset)
          Sets the character set encoding.
 void setContent(java.io.File inFile, java.lang.String type)
          Sets message content from file represented by File object.
 void setContent(java.io.File inFile, java.lang.String type, java.lang.String externalPlainText)
          Sets message content from file represented by File object.
 void setContent(java.io.InputStream content, java.lang.String type)
          Sets message content from InputStream.
 void setContent(java.io.InputStream content, java.lang.String type, java.lang.String externalPlainText)
          Sets message content from InputStream.
 void setContent(java.io.InputStream content, java.lang.String type, java.lang.String path, java.io.InputStream[] resources)
          Sets message content from InputStream.
 void setContent(java.io.InputStream content, java.lang.String type, java.lang.String path, java.io.InputStream[] resources, java.lang.String externalPlainText)
          Sets message content from InputStream.
 void setContent(java.lang.String content, java.lang.String type)
          Sets message content from String.
 void setContent(java.lang.String content, java.lang.String type, java.lang.String externalPlainText)
          Sets message content from String.
 void setContent(java.lang.String content, java.lang.String type, java.lang.String path, java.io.InputStream[] resources)
          Sets message content from String.
 void setContent(java.lang.String content, java.lang.String type, java.lang.String path, java.io.InputStream[] resources, java.lang.String externalPlainText)
          Sets message content.
 void setReply(java.lang.String replyAddress)
          Sets REPLY TO field in message header.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

message

protected javax.mail.internet.MimeMessage message
Container for MIME message


contentPresence

protected boolean contentPresence
Indicator of the email message content part presence (it can be plain text or html content). Other part of message contains attachements.


externalMessagePresence

protected boolean externalMessagePresence
Indicator of the external MimeMessage object presence. This parameter is true when constructor with MimeMessage object is used.


bodyPartArray

protected java.util.Vector bodyPartArray
Storage for MIME bodyparts


certArray

protected java.util.Vector certArray
Storage for .cer files coresponding to appropriate enveloping session


indicatorTo

protected boolean indicatorTo
Indication that at least one recipient must be TO (others may be CC or BCC)


charsetEnc

protected java.lang.String charsetEnc
Character set definition. The given Unicode strings will be charset-encoded by using theis attribute. The charset is also used to set the "charset" parameter. For example German letters should be encoded by usage of 'ISO-8859-1' charset. If charset parameter is null and subject or content contains non US-ASCII characters, it will be encoded using the platform's default charset. For more information about character sets refer to 'Character Encodings' chapter of package java.lang Java documentation page, or to RFC2278.

Constructor Detail

BaseSMIMEObject

protected BaseSMIMEObject()
Simple constructor. Dynamically loads the BC and SUN provider necessary for cryptography processing. This constructor does not create MIME message object, so it is obligatory to invoke initMimeMessage() method after this constructor.


BaseSMIMEObject

protected BaseSMIMEObject(java.lang.String smtpHost,
                          java.lang.String fromAddress,
                          java.lang.String subject,
                          java.lang.String content,
                          java.lang.String charset)
                   throws SMIMEException
Initializes the JavaMail session for SMTP and the MimeMessage object for message which will be sent. Dynamically loads the BC and SUN provider necessary for cryptography processing. This constructor is used for creating message with text/plain content. For creating html formated content (text/html), other constructor should be used in combination with one of setContent methods. Note that after using this constructor setContent method can be used only if "content" argument of constructor was given as null, otherwise setContent method can't be used because content is already set as text/plain.

Parameters:
smtpHost - name of SMTP host used for sending email
fromAddress - email address of sender (FROM field in email header)
subject - subject of email (SUBJECT field in email header). This argument can be null, but email message will be sent withouth SUBJECT.
content - text/plain content of email message. This argument can be null, but later one of setContent() methods or one of addAttachment() methods should be called
charset - character set for passed subject and content. The given Unicode string will be charset-encoded using the specified charset. The charset is also used to set the "charset" parameter. For example German letters should be encoded by usage of 'ISO-8859-1' charset. If charset parameter is null and subject or content contains non US-ASCII characters, it will be encoded using the platform's default charset.
Throws:
SMIMEException - if smtpHost or fromAddress parameters are null. Also, it can be caused by non SMIMEException which is MessagingException.

BaseSMIMEObject

protected BaseSMIMEObject(java.lang.String smtpHost,
                          java.lang.String fromAddress,
                          java.lang.String subject,
                          java.lang.String charset)
                   throws SMIMEException
Initializes the JavaMail session for SMTP and the MimeMessage object for message which will be sent. Dynamically loads the BC and SUN provider necessary for cryptography processing. This constructor does not create content of message and it can be set later with one of setContent methods. Also, message can be left withouth content, but then at least one attachement must be added.

Parameters:
smtpHost - name of SMTP host used for sending email
fromAddress - email address of sender (FROM field in email header)
subject - subject of email (SUBJECT field in email header). This argument can be null, but email message will be sent withouth SUBJECT.
charset - character set for passed subject and content. The given Unicode string will be charset-encoded using the specified charset. The charset is also used to set the "charset" parameter. For example German letters should be encoded by usage of 'ISO-8859-1' charset. If charset parameter is null and subject or content contains non US-ASCII characters, it will be encoded using the platform's default charset.
Throws:
SMIMEException - if smtpHost or fromAddress parameters are null. Also, it can be caused by non SMIMEException which is MessagingException.

BaseSMIMEObject

protected BaseSMIMEObject(javax.mail.internet.MimeMessage mimeMessage)
                   throws SMIMEException
Construction of message with external prepared MimeMessage object. Usage of this constructor disables usage of setContent() and addAttachment() methods. Also, all recipients (TO, CC or BCC type) must be declared again via setRecipient() method, even if they were previously set. Be very carefull with usage of this constructor because all MimeBodyPart objects and MimeMultipart objects used in construction of given MimeMessage object, must have correct defined Content header arguments, and contents. Contents must be formed in format which can be recognised and appropriate interpreted in the process of sending mail. If there is any special content object added to MimeBodyPart object or MimeMultipart object, the appropriate DataContent handler must be created for that object and set to corresponding BodyPart.

Parameters:
mimeMessage - external created MimeMessage object
Throws:
SMIMEException - if smtpHost or fromAddress parameter is null. Also, it can be caused by non SMIMEException which is MessagingException.
Method Detail

initMimeMessage

public void initMimeMessage(java.lang.String smtpHost,
                            java.lang.String fromAddress,
                            java.lang.String subject,
                            java.lang.String content,
                            java.lang.String charset)
                     throws SMIMEException
Initializes the JavaMail session for SMTP and the MimeMessage object for message which will be sent. If the argument 'content' is not given as null this method is used for creating new message with text/plain content. For creating html formated content (text/html), argument 'content' should be given as null, and content of message should be set with one of setContent methods. Note that after using initMimeMessage method, setContent method can be used only if 'content' argument of constructor was given as null, otherwise setContent method can't be used because content is already set as text/plain.

Parameters:
smtpHost - name of SMTP host used for sending email
fromAddress - email address of sender (FROM field in email header)
subject - subject of email (SUBJECT field in email header). This argument can be null, but email message will be sent withouth SUBJECT.
content - text/plain content of email message
charset - character set for passed subject and content. The given Unicode string will be charset-encoded using the specified charset. The charset is also used to set the "charset" parameter. For example German letters should be encoded by usage of 'ISO-8859-1' charset. If 'charset' argument is null and subject or content contains non US-ASCII characters, it will be encoded using the platform's default charset.
Throws:
SMIMEException - if smtpHost or fromAddress parameters are null. Also, it can be caused by non SMIMEException which is MessagingException.

setCharsetEncoding

public void setCharsetEncoding(java.lang.String charset)
Sets the character set encoding. This attribute also can be set during the construction of object, or by invoking initMimeMessage() method. By invoking this method, previously set parameter will be overriden.

Parameters:
charset - characterset encoding definition which will be used in process of string to byte array (and vice versa) transformation. The 'charset' argument is also used to set the 'charset' parameter in message or body header. For example German letters should be encoded by usage of 'ISO-8859-1' charset. If 'charset' argument is null and String contains non US-ASCII characters it will be encoded using the platform's default charset.

setContent

public void setContent(java.lang.String content,
                       java.lang.String type,
                       java.lang.String path,
                       java.io.InputStream[] resources,
                       java.lang.String externalPlainText)
                throws SMIMEException
Sets message content. Message content can be given in two differrent forms: text and html code. If content is type of text, parameter "type" should be "text/plain" and other two parameters are not in use (should be set to null). If content is type of html code, parameter "type" should be set as "text/html", otherwise (if it is set as "text/plain") html code is processed as plain text. This method can be performed only once.

In case of html content, it is essential to (on appropriate way) associate some attributes of particular elements in html code ("background" or "src" atributes) with corresponding ressources (URL-s, relative file addresses or byte array streams). This resources should all be sent with message to enable recipient to see complete html message. Location of resources can be given in few different forms and depending on that, allocation resolving can be successful or not. Following text represents different possibilities for defining locations of resources (pictures, animations, sound...) inside of html code passed to this method, and necessery passed additional parameters used for resolving this resource locations.


All mentioned resource allocation types can be combined together in the same html code, and all will be processed with appropriate use of this method.

Note that number of resource references that are defined in html code by using virtual_file_names must be greater than or equal to number of elements in array of InputStream (4th parameter). If one resource (one element in array of IputStream) is used in html code more than once, it is advisable to use same virtual_file_name in html code because message is then sent with only one attached resource (image, movie...). It is essetntial that desired resource in input stream array corresponds to specified "nnn" part of virtual_file_name.

If resources specified on any described name can not be found or resolved, or if any exception has occured during its processing, they won't be added and html message will be sent withouth them.

Parameters:
content - String representation of message content (text or html code). This argument is mandatory.
type - type of given content. It can take values: "text/plain" or "text/html". This argument is mandatory.
path - common directory path for relative file locations in html code. It can be null if all resources set absolute path or are defined by byte array streams, or if sending resources with relative address it is not desired. Also, it is set to null in case of text/plain message.
resources - way for representing resources used in the given html code which will be added to message as array of InputStream. Detail use of this argument is described above. It can be null if no resources as byte array stream are used, or if sending resources given in that way is not desired. Also, it is set to null in case of text/plain message.
externalPlainText - external text/plain message represented as String. This argument is used as alternative message to given html message in the process of generation multipart/alternative MimeMultipart message. If this argument has value null then autogeneration of text/plain message is performed according to passed html code (content argument). Also, it is set to null in case of text/plain message.
Throws:
SMIMEException - if content is tried to be added twice, or in case of wrong "type" parameter. Also, it can be caused by non SMIMEException which can be one of the following: MessagingException UnsoportedEncodingException.

setContent

public void setContent(java.lang.String content,
                       java.lang.String type,
                       java.lang.String path,
                       java.io.InputStream[] resources)
                throws SMIMEException
Sets message content from String. This method can be performed only once. Method is the same as corresponding method setContent with five parameters, where fifth parameter is set to null. This setContent method (in case that second argument - type has value text/html) is used with autogeneration of text/plain message according to given html code in the process of generation multipart/alternative MimeMultipart message. For further information refer to setContent method with five arguments.

Parameters:
content - String representation of message content (text or html code). This argument is mandatory.
type - type of given content. It can take values: "text/plain" or "text/html". This argument is mandatory.
path - common directory path for relative file locations in html code. It can be null if all resources set absolute path or are defined by byte array streams, or if sending resources with relative address it is not desired. Also, it is set to null in case of text/plain message.
resources - way for representing resources used in the given html code which will be added to message as array of InputStream. Detail use of this argument is described above. It can be null if no resources as byte array stream are used, or if sending resources given in that way is not desired. Also, it is set to null in case of text/plain message.
Throws:
SMIMEException - if content is tried to be added twice, or in case of wrong "type" parameter. Also, it can be caused by non SMIMEException which can be one of the following: MessagingException UnsoportedEncodingException.

setContent

public void setContent(java.io.InputStream content,
                       java.lang.String type,
                       java.lang.String path,
                       java.io.InputStream[] resources,
                       java.lang.String externalPlainText)
                throws SMIMEException
Sets message content from InputStream. This method can be performed only once. Message content can be given in two differrent forms: text and html code. If content is type of text, parameter "type" should be "text/plain", while if content is type of html code, parameter "type" should be set as "html/code". For further information refer to setContent method with five arguments (String, String, String, InputStream[], String) which is called by this method.

Parameters:
content - message content data given from any InputStream. Data can be text or html code and will be interpreted according to second parameter: "type".
type - type of given content. It can take values: "text/plain" or "text/html". This argument is mandatory.
path - common directory path for relative file locations in html code. It can be null if all resources in html code have set absolute path or are defined by byte array streams, or if sending resources with relative address is not desired. Also, it is set to null in case of text/plain message.
resources - way for representing resources used in the given html code which will be added to message as array of InputStreams. Detail use of this argument is described in other setContent methods mentioned before. It can be null if no resources as byte array stream are used, or if sending resources given in that way is not desired. Also, it is set to null in case of text/plain message.
externalPlainText - external text/plain message represented as String. This argument is used as alternative message to given html message in the process of generation multipart/alternative MimeMultipart message. If this argument has value null then autogeneration of text/plain message is performed according to passed html code (content argument). Also, it is set to null in case of text/plain message.
Throws:
SMIMEException - if content is tried to be added twice , in case of wrong "type" parameter or in case when parameter content is null. Also, it can be caused by non SMIMEException which is MessagingException.

setContent

public void setContent(java.io.InputStream content,
                       java.lang.String type,
                       java.lang.String path,
                       java.io.InputStream[] resources)
                throws SMIMEException
Sets message content from InputStream. This method can be performed only once. Method is same as corresponding method setContent with five parameters, where fifth parameter is set to null. This setContent method (in case that second argument - type has value text/html) is used with autogeneration of text/plain message according to given html code in process of generation multipart/alternative MimeMultipart message. For further information refer to setContent method with five arguments (InputStream, String, String, InputStream[], String) which is called by this method.

Parameters:
content - message content data given from any InputStream. Data can be text or html code and will be interpreted according to second parameter: "type".
type - type of given content. It can take values: "text/plain" or "text/html". This argument is mandatory.
path - common directory path for relative file locations in html code. It can be null if all resources in html code have set absolute path or are defined by byte array streams, or if sending resources with relative address is not desired. Also, it is set to null in case of text/plain message.
resources - way for representing resources used in the given html code which will be added to message as array of InputStreams. Detail use of this argument is described in other setContent methods mentioned before. It can be null if no resources as byte array stream are used, or if sending resources given in that way is not desired. Also, it is set to null in case of text/plain message.
Throws:
SMIMEException - if content is tried to be added twice , in case of wrong "type" parameter or in case when parameter content is null. Also, it can be caused by non SMIMEException which is MessagingException.

setContent

public void setContent(java.io.InputStream content,
                       java.lang.String type,
                       java.lang.String externalPlainText)
                throws SMIMEException
Sets message content from InputStream. This method can be performed only once. Message content can be given in two differrent forms: text and html code. If content is type of text, parameter "type" should be "text/plain", while if content is type of html code, parameter "type" should be set as "html/code". If html code content is set by this method, message will be generated withouth inclusion of the resources defined in paricular html element's attribute ("src" and "background"). Only plain html code will be sent and any reference to local file system resources will be useless for recipient of the message. HTTP referenced resources can still be available if recipient is online on Internet. Message generated on this way is smaller so encrypting process should be faster.

Parameters:
content - message content data given from any InputStream. Data could be text or html code and will be interpreted according to second parameter: "type". This argument is mandatory.
type - type of given content. It can take values: "text/plain" or "text/html". This argument is mandatory.
externalPlainText - external text/plain message represented as String. This argument is used as alternative message to given html message in the process of generation multipart/alternative MimeMultipart message. If this argument has value null then autogeneration of text/plain message is performed according to passed html code (content argument). Also, it is set to null in case of text/plain message.
Throws:
SMIMEException - if content is tried to be added twice , in case of wrong "type" parameter or in case when parameter content is null. Also, it can be caused by non SMIMEException which is MessagingException.

setContent

public void setContent(java.io.InputStream content,
                       java.lang.String type)
                throws SMIMEException
Sets message content from InputStream. This method can be performed only once. Method is the same as corresponding method setContent with three parameters, where third parameter is set to null. This setContent method (in case that second argument - type has value text/html) is used with autogeneration of text/plain message according to given html code in the process of generation multipart/alternative MimeMultipart message. For further information refer to setContent method with thre arguments.

Parameters:
content - message content data given from any InputStream. Data could be text or html code and will be interpreted according to second parameter: "type". This argument is mandatory.
type - type of given content. It can take values: "text/plain" or "text/html". This argument is mandatory.
Throws:
SMIMEException - if content is tried to be added twice , in case of wrong "type" parameter or in case when parameter content is null. Also, it can be caused by non SMIMEException which is MessagingException.

setContent

public void setContent(java.lang.String content,
                       java.lang.String type,
                       java.lang.String externalPlainText)
                throws SMIMEException
Sets message content from String. This method can be performed only once. Message content can be given in two differrent forms: text and html code. If content is type of text, parameter "type" should be "text/plain", while if content is type of html code, parameter "type" should be set as "html/code". If html code content is set by this method, message will be generated withouth inclusion of the resources defined in paricular html element's attribute ("src" or "background"). Only plain html code will be sent and any reference to local file system resources will be useless for recipient of the message. HTTP referenced resources can still be available if recipient is online on Internet. Message generated on this way is smaller, so encrypting process should be faster.

Parameters:
content - message content data given as String which can be text or html code and will be interpreted according to second parameter: "type". This argument is mandatory.
type - type of given content. It can take values: "text/plain" or "text/html". This argument is mandatory.
externalPlainText - external text/plain message represented as String. This argument is used as alternative message to given html message in the process of generation multipart/alternative MimeMultipart message. If this argument has value null then autogeneration of text/plain message is performed according to passed html code (content argument). Also, it is set to null in case of text/plain message.
Throws:
SMIMEException - if content is tried to be added twice, or in case of wrong "type" parameter. Also, it can be caused by non SMIMEException which can be one of the following: MessagingException UnsoportedEncodingException.

setContent

public void setContent(java.lang.String content,
                       java.lang.String type)
                throws SMIMEException
Sets message content from String. This method can be performed only once. Method is same as corresponding method setContent with three parameters, where third parameter is set to null. This setContent method (in case that second argument - type has value text/html) is used with autogeneration of text/plain message according to given html code in the process of generation multipart/alternative MimeMultipart message. For further information refer to setContent method with three arguments.

Parameters:
content - message content data given as String which can be text or html code and will be interpreted according to second parameter: "type". This argument is mandatory.
type - type of given content. It can take values: "text/plain" or "text/html". This argument is mandatory.
Throws:
SMIMEException - if content is tried to be added twice , in case of wrong "type" parameter or in case when parameter content is null. Also, it can be caused by non SMIMEException which is MessagingException.

setContent

public void setContent(java.io.File inFile,
                       java.lang.String type,
                       java.lang.String externalPlainText)
                throws SMIMEException
Sets message content from file represented by File object. This method can be performed only once. Message content can be given in two differrent forms: text and html code. If content is type of text, parameter "type" should be "text/plain", while if content is type of html code, parameter "type" should be set as "html/code". Note that for this method, location of resources needed by html file (pictures, sounds... ) shouldn't be defined in html code as they should be passed as InputStream arrays. For further information refer to setContent method with five arguments (String, String, String, InputStream[], String) which is called by this method.

Parameters:
inFile - location of file which is used for content of the message. This argument is mandatory.
type - type of given content. It can take values: "text/plain" or "text/html". This argument is mandatory.
externalPlainText - external text/plain message represented as String. This argument is used as alternative message to given html message in the process of generation multipart/alternative MimeMultipart message. If this argument has value null then autogeneration of text/plain message is performed according to passed html code (content argument). Also, it is set to null in case of text/plain message.
Throws:
SMIMEException - if content is tried to be added twice, in case of wrong "type" parameter, or if passed file (as File object) does not exist in file sistem. Also, it can be caused by non SMIMEException which can be one of the following: MessagingException or IOException.

setContent

public void setContent(java.io.File inFile,
                       java.lang.String type)
                throws SMIMEException
Sets message content from file represented by File object. This method can be performed only once. Method is the same as corresponding method setContent with three parameters, where third parameter is set to null. This setContent method (in case that second argument - type has value text/html) is used with autogeneration of text/plain message according to given html code in the process of generation multipart/alternative MimeMultipart message. For further information refer to corresponding setContent method with thre arguments.

Parameters:
inFile - location of file which is used for content of the message. This argument is mandatory.
type - type of given content. It can take values: "text/plain" or "text/html".
Throws:
SMIMEException - if content is tried to be added twice , in case of wrong "type" parameter or in case when parameter content is null. Also, it can be caused by non SMIMEException which is MessagingException.

addAttachment

public void addAttachment(java.lang.String fileName)
                   throws SMIMEException
Adds file as attachment to email message. Content-Type will be automatically detected. Note that for linux files, if they are recognised as files with text/... MIME Content-Type, line breaks (LF) will be transformed to Windows line breaks (CRLF). Same transformation will be performed to single Carriage Return (CR) character. If linux textual file should be transported via email untouched, the best solution is to force usage of BASE64 encoding with other addAttachment() method.

Parameters:
fileName - path and file name used for attachment
Throws:
SMIMEException - if passed file (as File object) does not exist in the file sistem. Also, it can be caused by non SMIMEException which is MessagingException

addAttachment

public void addAttachment(java.lang.String fileName,
                          java.lang.String encoding)
                   throws SMIMEException
Adds file as attachment to email message with given value for prefered Content-Transfer-Encoding argument. Attachment will be encoded acording to this parameter. Be carful with usage of this method, because you must know nature and content of file well, to avoid errors in encoding. Since this method does not employ automatic detection of Content-Transfer-Encoding, it is sligtly faster. Note that for linux textual files, if they are encoded as quoted-printable, line breaks (LF) will be transformed to Windows line breaks (CRLF). Same transformation will be performed to single Carriage Return (CR) character. If linux textual file should be transported via email untouched, the best solution is to force usage of BASE64 encoding.

Parameters:
fileName - path and file name used for attachment
encoding - Content-Transfer-Encoding value. It can take values: 7bit, quoted-printable, and base64
Throws:
SMIMEException - if passed file (as File object) does not exist in the file sistem. Also, it can be caused by non SMIMEException which is MessagingException

addAttachment

public void addAttachment(java.io.File file)
                   throws SMIMEException
Adds file as attachment to email message. Content-Type will be automatically detected. Note that for linux files, if they are recognised as files with text/... MIME Content-Type, line breaks (LF) will be transformed to Windows line breaks (CRLF). Same transformation will be performed to single Carriage Return (CR) character. If linux textual file should be transported via email untouched, the best solution is to force usage of BASE64 encoding with other addAttachment() method.

Parameters:
file - used for attachment represented as File object
Throws:
SMIMEException - if passed file (as File object) does not exist in the file sistem. Also, it can be caused by non SMIMEException which is MessagingException or IOException

addAttachment

public void addAttachment(java.io.File file,
                          java.lang.String encoding)
                   throws SMIMEException
Adds file as attachment to email message with given value for prefered Content-Transfer-Encoding argument. Attachment will be encoded acording to this parameter. Be carful with usage of this method, because you must know nature and content of file well, to avoid errors in encoding. Since this method does not employ automatic detection of Content-Transfer-Encoding, it is sligtly faster. Note that for linux textual files, if they are encoded as quoted-printable, line breaks (LF) will be transformed to Windows line breaks (CRLF). Same transformation will be performed to single Carriage Return (CR) character. If linux textual file should be transported via email untouched, the best solution is to force usage of BASE64 encoding.

Parameters:
file - path and file name used for attachment
encoding - Content-Transfer-Encoding value. It can take values: 7bit, quoted-printable, and base64
Throws:
SMIMEException - if passed file (as File object) does not exist in the file sistem. Also, it can be caused by non SMIMEException which is MessagingException

addAttachment

public void addAttachment(java.io.InputStream data,
                          java.lang.String fileName)
                   throws SMIMEException
Adds data from InputStream as attachment to email message. Content-Type will be automaticaly detected. Note that for linux files (virtual or real), if they are recognised as files with text/... MIME Content-Type, line breaks (LF) will be transformed to Windows line breaks (CRLF). Same transformation will be performed to single Carriage Return (CR) character. If linux textual file should be transported via email untouched, the best solution is to force usage of BASE64 encoding with other addAttachment() method.

Parameters:
data - byte array from InputStream
fileName - virtual or real file name (wihouth path). Correct information about name; extension of file name is especially important. Name is used in construction of "name" parameter in Content-Type header line of body parts of mime message. Extension of file is used in detection of the appropriate mime-type.
Throws:
SMIMEException - caused by non SMIMEException which is MessagingException

addAttachment

public void addAttachment(java.io.InputStream data,
                          java.lang.String fileName,
                          java.lang.String encoding)
                   throws SMIMEException
Adds data from InputStream as attachment to email message with given value for prefered Content-Transfer-Encoding argument. Attachment will be encoded acording to this parameter. Be carful with usage of this method, because you must know nature and content of file well, to avoid errors in encoding. Since this method does not employ automatic detection of Content-Transfer-Encoding, it is sligtly faster. Note that for linux textual files, if they are encoded as quoted-printable, line breaks (LF) will be transformed to Windows line breaks (CRLF). Same transformation will be performed to single Carriage Return (CR) character. If linux textual file should be transported via email untouched, the best solution is to force usage of BASE64 encoding.

Parameters:
fileName - path and file name used for attachment
encoding - Content-Transfer-Encoding value. It can take values: 7bit, quoted-printable, and base64
Throws:
SMIMEException - if passed file (as File object) does not exist in the file sistem. Also, it can be caused by non SMIMEException which is MessagingException

addRecipient

protected void addRecipient(java.lang.String recipientAddress,
                            java.lang.String type,
                            java.lang.String cerFileName)
                     throws SMIMEException
Adds recipient address, type and .cer file of email recipient to encrypted message. Certificate file should be passed only in the case of Enveloped message or Signed and Enveloped message. Otherwise this argument represents redundance value and it should be given as null.

Parameters:
recipientAddress - email address of recipent (fields TO or CC or BCC in email message header)
type - should be TO, CC or BCC
cerFileName - path and file name with certificate corresponding to recipient (file with .cer extension)
Throws:
SMIMEException - if type of addressing of messages is not TO, CC or BCC. Also, it can be caused by non SMIMEException which can be one of the following: IOException, MessagingException, FileNotFoundException, NoSuchProviderException, CertificateException.

addRecipient

protected void addRecipient(java.lang.String recipientAddress,
                            java.lang.String type,
                            java.security.KeyStore kStore,
                            java.lang.String alias)
                     throws SMIMEException
Adds recipient address, type and recipient's certificate via KeyStore object and apropriate alias. Certificate information should be passed only in the case of Enveloped message or Signed and Enveloped message. Otherwise those arguments represent redundance values and they should be given as null.

Parameters:
recipientAddress - email address of recipent (fields TO or CC or BCC in email message header)
type - should be TO, CC or BCC
kStore - instance of KeyStore class which represents an in-memory collection of keys and certificates.
alias - alias name which corresponds to desired certificate. If alias is given as null, then reading results are unpredictable.
Throws:
SMIMEException - if type of addressing of messages is not TO, CC or BCC. Also, it can be caused by non SMIMEException which can be one of the following: IOException, MessagingException, FileNotFoundException, NoSuchProviderException, CertificateException.

addRecipient

protected void addRecipient(java.lang.String recipientAddress,
                            java.lang.String type,
                            java.lang.String ksPath,
                            java.lang.String ksType,
                            java.lang.String password,
                            java.lang.String alias)
                     throws SMIMEException
Adds recipient address, type and recipient's certificate via path to the KeyStore file, KeyStore type, password and apropriate alias. Certificate information should be passed only in the case of Enveloped message or Signed and Enveloped message. Otherwise those arguments represent redundance values and they should be given as null.

Parameters:
recipientAddress - email address of recipent (fields TO or CC or BCC in email message header)
type - should be TO, CC or BCC
ksPath - is path to the file representation of KeyStore which holds collection of keys and certificates. This file can be PKCS12 type (file with .p12 or .pfx extension) or can be key store of other types readable by 'BouncyCastle' or 'Sun' KeyStore implementation.
ksType - is type of KeyStore. It can be one of the following types: JKS for 'Sun' KeyStore, 'BKS', 'PKCS12' or 'UBER') for 'BouncyCastle' KeyStore. If ksType is given as null it will be assumed that .cer file is in use, and alias parameter will be ignored, so this method becomes equivalent to addRecipient() method which deal only with .cer files.
password - password used to access the corresponding private key, stored in given KeyStore file.
alias - alias name which corresponds to desired private key. If alias is given as null, then reading results are unpredictable. to recipient (file with .cer extension)
Throws:
SMIMEException - if type of addressing of messages is not TO, CC or BCC. Also, it can be caused by non SMIMEException which can be one of the following: IOException, MessagingException, FileNotFoundException, NoSuchProviderException, CertificateException.

setReply

public void setReply(java.lang.String replyAddress)
              throws SMIMEException
Sets REPLY TO field in message header.

Parameters:
replyAddress - email address used in reply
Throws:
SMIMEException - caused by non SMIMEException which is MessagingException. Also, javax.mail.internet.AddressException is thrown from instances of InternetAddress class (but AddressException extends MessagingException).

getMimeMessage

public javax.mail.internet.MimeMessage getMimeMessage()
Returns MimeMessage.

Returns:
Signed S/MIME message

reset

public void reset()
Resets all attributes in BaseSMIMEObject to their initial values. The attributes have the same values as when simple construcor is invoked. It means that after this method call, MIME message object should be rebuild again by calling initMimeMessage() method and optionaly other setContent() and addAttachment() method calls.


send

public void send()
          throws javax.mail.MessagingException
Sends S/MIME message to SMTP host.

Throws:
javax.mail.MessagingException - caused by use of methods from objects of class Transport.

Enhydra-Oyster 2.1-7 API