Receiving email with attachment using JavaMail API

As we receive the email, we can receive the attachment also by using Multipart and BodyPart classes.

For better understanding of this example, learn the steps of sending email using JavaMail API first.
For receiving or sending the email using JavaMail API, you need to load the two jar files:
  • mail.jar
  • activation.jar
download these jar files (or) go to the Oracle site to download the latest version.

Example of receiving email with attachment using JavaMail API

Load the jar file c:\> set classpath=mail.jar;activation.jar;.;
compile the source file c:\> javac ReadAttachment.java
run by c:\> java ReadAttachment