Home Javamail Handle EML(Electronic mail) file with Java Mail
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Handle EML(Electronic mail) file with Java Mail

Advertisement
This Example shows you how to read any eml(Electronic mail) file using javamail api. eml is a simple email, all eml are stored in Folder objects. folders can contain folders or messages.

Handle EML(Electronic mail) file with Java Mail

     

This Example shows you how to read any eml(Electronic mail) file using javamail api. eml is a simple email, all eml are stored in Folder objects. folders can contain folders or messages. The Folder class declares methods that fetch, append, copy and delete messages.
EML are saved email messages from Outlook or other Email application. These files having extension .eml .

EML.java


import java.io.*;
import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;

public class EML {

  public static void main(String args[]) throws Exception {

  String host = "192.168.10.205";
  String from = "test@localhost";
  String to = "test@localhost";

  Properties props = System.getProperties();
  props.setProperty("mail.smtp.host", host);
  props.put("mail.transport.protocol""smtp");

  Session mailSession = Session.getDefaultInstance(props, null);

  File emlFile = new File("message.eml");
  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());
  }
}

Output:

------------ Message ------------
Return-Path: <test@localhost>
Delivered-To: test@localhost
Received: from 192.168.10.111 ([192.168.10.111])
  by roseindi-iyo058 (JAMES SMTP Server 2.3.1with SMTP ID 18
  for <test@localhost>;
  Wed, 16 Jul 2008 14:33:32 +0000 (GMT)
Date: Wed, 16 Jul 2008 14:33:32 +0000 (GMT)
From: test@localhost
To: test@localhost
Message-ID: <6794265.0.1216195417823.JavaMail.komal@komal>
Subject: hi..!
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Download code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 19, 2008

Related Tutorials

Ask Questions?    Discuss: Handle EML(Electronic mail) file with Java Mail  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Satheesh
September 14, 2012
Out put problem

Kindly provide solution for this issue: OUTPUT: Subject : Re: language From : "Satheesh.Kumar" <xxx.xxx@xxxx.co.in> -------------- Body : javax.mail.internet.MimeMultipart@1eec612 I can't get Message. Please help me.
DMCA.com