Java
  Home arrow Java arrow Page 5 - Java Mail API: Transforming Mail into Data...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Java Mail API: Transforming Mail into Data Carriers
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2005-11-22

    Table of Contents:
  • Java Mail API: Transforming Mail into Data Carriers
  • Java Mail Core Classes Continued
  • Mails As Data Carriers: A Practical Approach
  • Sending
  • Receiving

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Java Mail API: Transforming Mail into Data Carriers - Receiving


    (Page 5 of 5 )

    That is all there for sending. Now let's look at receiving. For this, another function, recvDocument, will be defined. It will take the Message object as a parameter.

    boolean recvDocument(Message message)
    {
    Multipart mp = (Multipart)message.getContent();

    for (int i=0, n=multipart.getCount(); i<n; i++) {
      Part part = multipart.getBodyPart(i));

      String disposition = part.getDisposition();

      if ((disposition != null) &&
          ((disposition.equals(Part.ATTACHMENT) ||
           (disposition.equals(Part.INLINE))) {
        saveFile(part.getFileName(), part.getInputStream());
      }
    }
    }

    The function creates a Multipart from the message object. Then, until the parts are completed, it is read, checked for deposition (flagging of boundary of attachments) and sent to a function that saves the file by reading from the stream. Due to the simplicity of the save() function, it is not being shown here. That completes the sending and receiving of data documents.

    It should be evident from the code how easy it is to make Java Mail API to work as a data carrier. Though this is a different usage of the mailing system, it proves that any API, if viewed from a different perspective, can provide new solutions to old problems. That brings us to the end of this tutorial on Java Mail API. I hope it has provided you with an insight into what can be achieved with Java Mail. Using it for data transfer is just one of many approaches. Dig deeper and you will find many more approaches. Till next time.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · HiThank you for reading this article. It details about using Mail API as data...
     

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway