Getting the message headers

Top  Previous  Next

You may get all headers for a message using the MimeMessage#getHeaders method.  This will return a java.util.Enumeration of MimeHeader.  To retrieve a named header you may use the MimeMessage#getHeader method passing in the header name as a String argument.  This will return the first matching MimeHeader or null if a matching header is not found.  See the JavaDoc on the MimeMessage and MimeHeader classes for more information.

 

Note

 

The MimeMessage#getHeaders method will only return the top-level headers for the MIME message.  Any headers found in parts of the message will not be returned.  You will need to access these parts separately to return their headers.

 

Example

 

// get all headers

Enumeration headers = msg.getHeaders();

 

while(headers.hasMoreElements()) {

 MimeHeader h = (MimeHeader)headers.nextElement();

 System.out.println(h.toString());

}

 

 

Example

 

// get Content-Type header

MimeHeader ct = msg.getHeader("Content-Type");

 

if(ct != null) {

 System.out.println(ct.toString());

}





Home | Company | Products | Solutions | Purchase | Support | Services | Blog

© 2021 JSCAPE LLC