
Originally Posted by
JavaPF
Hello gsanchezbiz,
Welcome to the Java Programming Forums.
Sorry for the late reply on this. I have compiled the code and it seems to work.
Just to clarify, you are looking to extract all of the Message-ID's? For example:
Message-ID:<CC3DADE7B22D134FB3F84E34B91F84800143A420@dghdc 001.dghmoney.local> I've had a play around with it and you should be able to do something like this:
import java.util.*; import javax.mail.*; public class msgshow { public static void main(String[] args) throws Exception { Properties props = System.getProperties(); props.setProperty("mail.pop3.port", "995"); Session session = Session.getInstance(props, null); Store store = session.getStore("imaps"); store.connect("pop.gmail.com", "username", "password"); Folder inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_ONLY); //System.out.print(inbox.getMessageCount()); for (int i = 1;i <= 10; i++){ //System.out.println(h.getName() + ": " + h.getValue()); inbox.getMessage(i).getHeader("Message-Id"); Enumeration headers = inbox.getMessage(i).getAllHeaders(); while (headers.hasMoreElements()) { Header h = (Header) headers.nextElement(); //System.out.println(h.getName() + ":" + h.getValue()); //System.out.println(""); String mID = h.getName(); if(mID.contains("Message-ID")){ System.out.println(h.getName() + ":" + h.getValue()); } } } inbox.close(true); } } Thank you very much for this code, this is exactly what I was looking for... Although, for some reason there were a couple of emails where it couldn't find the Message-ID header even though I manually found it on those .eml files. After playing a bit with it, I noticed that for those emails it detected the header as Message-Id and I have no idea why, because on the file it has a capital D... So I just modified the line like this: if(mID.contains("Message-ID") || mID.contains("Message-Id"))