Search in sources :

Example 21 with URLDataSource

use of javax.activation.URLDataSource in project pentaho-kettle by pentaho.

the class Mail method addAttachedFilePart.

private void addAttachedFilePart(FileObject file) throws Exception {
    // create a data source
    MimeBodyPart files = new MimeBodyPart();
    // create a data source
    URLDataSource fds = new URLDataSource(file.getURL());
    // get a data Handler to manipulate this file type;
    files.setDataHandler(new DataHandler(fds));
    // include the file in the data source
    files.setFileName(file.getName().getBaseName());
    // insist on base64 to preserve line endings
    files.addHeader("Content-Transfer-Encoding", "base64");
    // add the part with the file in the BodyPart();
    data.parts.addBodyPart(files);
    if (isDetailed()) {
        logDetailed(BaseMessages.getString(PKG, "Mail.Log.AttachedFile", fds.getName()));
    }
}
Also used : URLDataSource(javax.activation.URLDataSource) DataHandler(javax.activation.DataHandler) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Aggregations

URLDataSource (javax.activation.URLDataSource)21 DataHandler (javax.activation.DataHandler)14 MimeBodyPart (javax.mail.internet.MimeBodyPart)11 URL (java.net.URL)9 DataSource (javax.activation.DataSource)9 MimeMultipart (javax.mail.internet.MimeMultipart)8 IOException (java.io.IOException)6 Multipart (javax.mail.Multipart)6 FileDataSource (javax.activation.FileDataSource)5 MimeMessage (javax.mail.internet.MimeMessage)5 InputStream (java.io.InputStream)4 Properties (java.util.Properties)4 Message (javax.mail.Message)4 Session (javax.mail.Session)4 InternetAddress (javax.mail.internet.InternetAddress)4 File (java.io.File)3 MessagingException (javax.mail.MessagingException)3 Date (java.util.Date)2 BodyPart (javax.mail.BodyPart)2 QName (javax.xml.namespace.QName)2