Holger's Java API

## com.antelmann.net.mail
Class Email

    java.lang.Object
      com.antelmann.net.mail.Email

All Implemented Interfaces:
  DetailedString, Forgeable<Email>, Serializable

    public class Email

extends Object
implements Serializable, Forgeable<Email>, DetailedString

Email represents an e-mail that could be sent through SMTP or received through POP3.

Since:
  5/30/2002
Author:
  Holger Antelmann
See Also:
  `POP3Account`, Serialized Form

Nested Class Summary
`static class` `Email.Attachment` Attachment represents an attachment to an email.
`static class` `Email.Header` A single Email may have several Header entries with the same name.

Field Summary
`static String` `ID_KEY`
`static String` `TEXT_HTML` can be used to set the type of the email
`static String` `TEXT_PLAIN` can be used to set the type of the email; this is the default

Constructor Summary
`Email()`
`Email(Email email)` constructs an Email object based on the parameters of the given one
`Email(javax.mail.Message msg)`

Method Summary
`boolean` `addAttachment(Email.Attachment attachment)`
`boolean` `addAttachment(File file)`
`boolean` `addAttachment(String fileName, byte[] content, String type)`
`void` `addHeader(String name, String value)` sets additional custom header
`void` `addParameter(String key, String value)` sets additional custom parameters (existing parameters are replaced)
`boolean` `containsInlineAttachment()`
`static String[]` `extractEmailAddresses(String addressLine)` uses javax.mail.internet.InternetAddress; may return an empty array if addressLine is null
`Email.Attachment[]` `getAttachments()` may return an empty array, but not null
`String` `getBCC()`
`String` `getCC()`
`Date` `getDeliveryDate()` looks for a header value where the name is 'Delivery-Date' and returns it (null is returned if no such header was found and a RuntimeException is thrown if the date could not be parsed)
`static String` `getDomain(String emailAddress)` works best if it is already determined that the given address is indeed a valid address
`String` `getFrom()`
`Email.Header[]` `getHeader()` returns all headers
`Set<String>` `getHeaderNames()` returns a set of String objects containing all header names
`String[]` `getHeaderValues(String name)`
`String` `getHtmlMessage()`
`static javax.mail.internet.InternetHeaders` `getInternetHeaders(Email.Header... header)`
`String` `getMessageID()` looks for a header value where the name is 'Message-ID' and returns it (null is returned if no such header was found)
`Map<String,String>` `getParameters()` returns additional custom parameters where String values are mapped to Sting values
`String` `getParameterValue(String key)`
`Date` `getSentDate()`
`int` `getSize()`
`String` `getSubject()`
`String` `getTextMessage()`
`String` `getTo()`
`boolean` `hasAttachments()`
`static boolean` `isValidAddressLine(String address)`
`static boolean` `isValidEmail(String emailAddress)` checks for RFC822 consistency and some other commonly useful things
`void` `openEmailClient()` opens the native email client prefilled with the information of this email
`boolean` `removeAttachment(Email.Attachment attachment)`
`boolean` `removeHeader(Email.Header h)`
`String` `removeParameter(String key)`
`void` `setAllFrom(Email email)` copies the properties of the given object and applies them to this instance, so that its behavior in regards to the given object can be matched to the extend that the implementing class supports that behavior.
`void` `setBCC(String bcc)`
`void` `setCC(String cc)`
`void` `setFrom(String from)`
`void` `setHtmlMessage(String html)`
`void` `setSentDate(Date date)`
`void` `setSize(int size)`
`void` `setSubject(String subject)`
`void` `setTextMessage(String message)`
`void` `setTo(String to)`
`String` `toDetailedString()` provides full details of this instance in a String.
`String` `toString()`
`static void` `validateAddressLine(String address)` validates an address line that can contain one or more addresses.
`static void` `validateEmail(String emailAddress)` checks for RFC822 consistency and some other commonly useful things; no connection to the Internet is made, though

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### ID_KEY

    public static String ID_KEY

### TEXT_PLAIN

    public static final String TEXT_PLAIN

  can be used to set the type of the email; this is the default

  See Also:
    Constant Field Values

### TEXT_HTML

    public static final String TEXT_HTML

  can be used to set the type of the email

  See Also:
    Constant Field Values

Constructor Detail

### Email

    public Email(Email email)

  constructs an Email object based on the parameters of the given one

### Email

    public Email()

### Email

    public Email(javax.mail.Message msg)
          throws javax.mail.MessagingException,
                 IOException

Throws:
  `javax.mail.MessagingException`
  `IOException`

Method Detail

### setAllFrom

    public void setAllFrom(Email email)

  Description copied from interface: `Forgeable`
  copies the properties of the given object and applies them to this instance, so that its behavior in regards to the given object can be matched to the extend that the implementing class supports that behavior.

  Specified by:
    `setAllFrom` in interface `Forgeable<Email>`
  Parameters:
    `email` - the object whose behavior is to be copied to this instance

### getMessageID

    public String getMessageID()

  looks for a header value where the name is 'Message-ID' and returns it (null is returned if no such header was found)

### getDeliveryDate

    public Date getDeliveryDate()

  looks for a header value where the name is 'Delivery-Date' and returns it (null is returned if no such header was found and a RuntimeException is thrown if the date could not be parsed)

### hasAttachments

    public boolean hasAttachments()

### getTo

    public String getTo()

### getFrom

    public String getFrom()

### getCC

    public String getCC()

### getBCC

    public String getBCC()

### getSubject

    public String getSubject()

### getTextMessage

    public String getTextMessage()

### getHtmlMessage

    public String getHtmlMessage()

### getSize

    public int getSize()

### getSentDate

    public Date getSentDate()

### setTo

    public void setTo(String to)

### setFrom

    public void setFrom(String from)

### setCC

    public void setCC(String cc)

### setBCC

    public void setBCC(String bcc)

### setSubject

    public void setSubject(String subject)

### setTextMessage

    public void setTextMessage(String message)

### setHtmlMessage

    public void setHtmlMessage(String html)

### containsInlineAttachment

    public boolean containsInlineAttachment()

### setSize

    public void setSize(int size)

### setSentDate

    public void setSentDate(Date date)

### getHeader

    public Email.Header[] getHeader()

  returns all headers

### getHeaderNames

    public Set<String> getHeaderNames()

  returns a set of String objects containing all header names

### getHeaderValues

    public String[] getHeaderValues(String name)

### addHeader

    public void addHeader(String name,
                          String value)

  sets additional custom header

### removeHeader

    public boolean removeHeader(Email.Header h)

### getParameters

    public Map<String,String> getParameters()

  returns additional custom parameters where String values are mapped to Sting values

### getParameterValue

    public String getParameterValue(String key)

### addParameter

    public void addParameter(String key,
                             String value)

  sets additional custom parameters (existing parameters are replaced)

### removeParameter

    public String removeParameter(String key)

### addAttachment

    public boolean addAttachment(File file)
                          throws IOException

  Throws:
    `IOException`

### addAttachment

    public boolean addAttachment(String fileName,
                                 byte[] content,
                                 String type)

### addAttachment

    public boolean addAttachment(Email.Attachment attachment)

### getAttachments

    public Email.Attachment[] getAttachments()

  may return an empty array, but not null

### removeAttachment

    public boolean removeAttachment(Email.Attachment attachment)

### toDetailedString

    public String toDetailedString()

  Description copied from interface: `DetailedString`
  provides full details of this instance in a String. In case the String contains multiple lines, it is recommended to use '\n' rather than the platform specific line-break for better compatibility.

  Specified by:
    `toDetailedString` in interface `DetailedString`
  Returns:
    a (potentially multi-line) String providing full details on this object instance

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

### openEmailClient

    public void openEmailClient()
                         throws IOException

  opens the native email client prefilled with the information of this email

  Throws:
    `IOException`
  See Also:
    `Desktop.mail(URI)`

### isValidEmail

    @ThirdParty(value="javax.mail.internet")
    public static boolean isValidEmail(String emailAddress)

  checks for RFC822 consistency and some other commonly useful things

  See Also:
    `POP3Account.getMXCount(String)`

### validateEmail

    @ThirdParty(value="javax.mail.internet")
    public static void validateEmail(String emailAddress)
                              throws javax.mail.internet.AddressException

  checks for RFC822 consistency and some other commonly useful things; no connection to the Internet is made, though

  Throws:
    `javax.mail.internet.AddressException`
  See Also:
    `POP3Account.getMXCount(String)`

### isValidAddressLine

    public static boolean isValidAddressLine(String address)

### getDomain

    public static String getDomain(String emailAddress)

  works best if it is already determined that the given address is indeed a valid address

  See Also:
    `isValidEmail(String)`

### validateAddressLine

    @ThirdParty(value="javax.mail.internet")
    public static void validateAddressLine(String address)
                                    throws javax.mail.internet.AddressException

  validates an address line that can contain one or more addresses.

  Throws:
    `javax.mail.internet.AddressException`

### extractEmailAddresses

    @ThirdParty(value="javax.mail.internet")
    public static String[] extractEmailAddresses(String addressLine)
                                          throws javax.mail.internet.AddressException

  uses javax.mail.internet.InternetAddress; may return an empty array if addressLine is null

  Throws:
    `javax.mail.internet.AddressException`

### getInternetHeaders

    public static javax.mail.internet.InternetHeaders getInternetHeaders(Email.Header... header)

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads