0

Quick question about about the .INLINE part of an attachment using the apache commons library.

Basically I'm supposed to send part of an excel sheet via mail showing said part inside the body of the message which, if I'm not mistaken, should be written like this:

attachment.setDisposition(EmailAttachment.INLINE);

now here's the issue: with my code I can easily send attached files which are only attachments and IF they're images I can also put them inline.

is there any way to get a portion of the xml file since it's formatted using apache POI? (I've found similar topics regarding the VBA - excel but I kind of need to implement this inside my program..also I'd like to send the selection as it was formatted if possible since it's quite good looking thanks to POI..)

the final result should be something like a copy/paste from the selected cells of the xml file appearing in the mail body but, since it's not an image, it won't be displayed correctly if I use only the .INLINE statement..I've even tried snapshotting the JTable component with no useful result.

Here's the code to send the email if it can help:

class SendEmail {
    public SendEmail() {

        // Create the attachment
        EmailAttachment attachment = new EmailAttachment();
        attachment.setPath("pathToFile");
        attachment.setDisposition(EmailAttachment.INLINE);
        attachment.setDescription("Xml File");
        attachment.setName("file.ods);

        // Create the email message
        MultiPartEmail email = new MultiPartEmail();
        email.setHostName("smtp.googlemail.com");
        email.setSmtpPort(587);
        email.setAuthenticator(new DefaultAuthenticator(
                "gmailAccount", "gmailAccountPwd"));
        email.setSSL(true);

        try {
            email.addTo("toRecipient");

            email.setFrom("fromRecipient");

            email.setSubject("Attached Mail Test");
            email.setMsg("This line should be followed by something..hopefully");

            // add the attachment
            email.attach(attachment);
            email.setTLS(true);

            // send the email
            email.send();

        } catch (EmailException e) {
            e.printStackTrace();
        }
    }
}

PS: please note that there's no trouble sending attached attachements or inline images..is that a limitation of the apache commons or am I just inexeperienced? (the latter stands still outside the topic though XD)

centic
  • 15,565
  • 9
  • 68
  • 125
Marchius
  • 115
  • 1
  • 3
  • 10
  • 1
    *"Quick question"* "What is the meaning of life?" is also a quick question. It is the ***answer*** that might take some time. Why should we care how quick it was for you to *ask* a question? ;) – Andrew Thompson Oct 08 '12 at 12:23
  • Did I just get trolled here!? =X On a serious note that doesn't really help not to count I actually spent time reading whole threads without finding an answer..it's not like I like bugging people on this forum if I can find the answer on my own.. :/ – Marchius Oct 08 '12 at 12:27
  • Oh come on. That was a slight 'poke in the ribs' to underline that the 'quickness' of questions is unrelated to the quickness of answers. Cheer up. People more focusing on the actual question will probably be along ..any minute now. – Andrew Thompson Oct 08 '12 at 12:31
  • Yeah don't worry, it's just that I hate asking since people here are helping out of their free time..I'm kind of sensitive on this subject <. – Marchius Oct 08 '12 at 12:37

0 Answers0