Java Mail API: Transforming Mail into Data Carriers
Java Mail is eminently adaptable. Indeed, looking at its API, we find that it helps us provide an alternative solution to an old problem: how to transfer large amounts of data between two enterprise applications. In this article, you will discover how to adapt Java Mail to play the role of a data carrier.
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.