Adding message headers |
Creating headers
A MIME header consists of a name, value and zero or more attributes. To create a simple MIME header use the MimeHeader class providing a name and value as arguments to the constructor.
Example
// create new MIME header MimeHeader header = new MimeHeader("Content-Disposition","attachment");
The example above would result in the following MIME header:
Content-Disposition: attachment
Adding attributes to headers
A MimeHeader may consist of 0 or more attributes. Each attribute consists of name and value. To add an attribute to a MIME header use the MimeHeader#addAttribute method and MimeHeaderAttr class.
Example
// create new MIME header MimeHeader header = new MimeHeader("Content-Disposition","attachment");
// create new header attribute MimeHeaderAttr filename = new MImeHeaderAttr("filename","test.jpg");
// add header attribute to header header.addAttribute(filename);
The example above would result in the following MIME header:
Content-Disposition: attachment; filename="test.jpg"
Adding headers
To add a header to a MimeMessage use the MimeMessage#addHeader method and MimeHeader classes.
Example
// create new MIME header MimeHeader header = new MimeHeader("Content-Disposition","attachment");
// create new header attribute MimeHeaderAttr filename = new MImeHeaderAttr("filename","test.jpg");
// add header attribute to header header.addAttribute(filename);
// create new MimeMessage MimeMessage msg = new MimeMessage();
// add header msg.addHeader(header);
|