0

Hi,
i'm trying to read a simple email file from a folder in my computer.
I find this code but, it's not working.

i didn't understand theses lines:
what should i write for mail.host?
what should i write for "mail.transport.protocol", "smtp"?

props.put("mail.host", "smtp.gmail.com");
props.put("mail.transport.protocol", "smtp");

import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;

public class ReadEmail {

   public static void main(String args[]) throws Exception{
       display(new File("C:\\temp\\message.eml"));

   }

   public static void display(File emlFile) throws Exception{
        Properties props = System.getProperties();
        props.put("mail.host", "smtp.gmail.com");
        props.put("mail.transport.protocol", "smtp");

        Session mailSession = Session.getDefaultInstance(props, null);
        InputStream source = new FileInputStream(emlFile);
        MimeMessage message = new MimeMessage(mailSession, source);


        System.out.println("Subject : " + message.getSubject());
        System.out.println("From : " + message.getFrom()[0]);
        System.out.println("--------------");
        System.out.println("Body : " +  message.getContent());
    }
}

Is there a simple way to just read an email file that i've already saved in a folder. I don't want to connect to my gmail.

Thank you
SPX

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by spalax
0

Thank you very much, it's really interesting for me.
SPX

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.