Description
Current State
The current API for creating a mail message with email attachments i.e.
// usage example (except) from documentation
Message message = Message.builder().attachment(ATTACHMENT_1)
// the builder method signatures
public Message.MessageBuilder attachment(File attachment)
public Message.MessageBuilder attachment(List<File> attachments)
The API utilises The java.io.File
class to indicate the resource to be included / attached to the email. From the File java doc An abstract representation of file and directory pathnames.
- Which means the API will only work for attachments, that are stored as files in a file filesystem.
Issue
In a server side application data (files) is generally not stored in a file system. It can be stored in a database or in another location or service. In my scenario the attachment is downloaded from a private web service via HTTPS.
To use the API I have to download the attachment and store it in as a local file system. This creates several issues based a double handling writing to and reading from the file system, performance, latency, resource use, etc
Enhancement
Like most modern programming languages Java support the concept of a stream data from a producer to consumer. This is in the form of the InputStream
and OutputStream
api's.
Ideally MessageBuilder
should be enhanced to support streaming of attachments, which vastly improves the flexibility for providing attachment data.