0

I use the apache commons-mail (v1.3.2) to send an order confirmation e-mail with a PDF as attachment. The e-mail displays without problems in outlook (both web and desktop) but when I send to my gmail account, the content of the mail is empty and the Html content is attached in a separate file "noname.html".

My code:

       // Create mail instance using commons-mail and the hybris MailUtility class.
        HtmlEmail htmlEmail = (HtmlEmail) MailUtils.getPreConfiguredEmail(); // creates a mail instance with set mail
        htmlEmail.setCharset("UTF-8");
        htmlEmail.setHtmlMsg("this is <b>html text</b>);

        // Part two is attachment
            DataSource ds = new ByteArrayDataSource(mailAttachment.getData(), "application/pdf");
            htmlEmail.attach(ds, "attach.pdf", "generalconditions", EmailAttachment.ATTACHMENT);
        }

        //send mail
        htmlEmail.send();

At first, this issue occured also in outlook but I fixed this by switching from commons-mail v1.1 to v1.3.2. Still not fixed for gmail though...

nexana
  • 1,096
  • 1
  • 9
  • 18
  • Because the getPreconfiguredEmail() method is from the Hybris MailUtils class.I thought it would be useful to add the tag, just in case it would be a known hybris issue. – nexana Jun 16 '14 at 14:07

1 Answers1

1

You should use

EmailAttachment attachment = new EmailAttachment();
attachment.setPath(pdfFile.getPath());
attachment.setDisposition(EmailAttachment.ATTACHMENT);

Then you attach it to the email like this :

htmlEmail.attach(attachment);
Captainju
  • 307
  • 1
  • 2
  • 10