[ https://issues.apache.org/jira/browse/EMAIL-28?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Henri Yandell updated EMAIL-28: ------------------------------- Fix Version/s: 1.1 > [email] Problems with HTML emails with attachments and embedded images > ---------------------------------------------------------------------- > > Key: EMAIL-28 > URL: https://issues.apache.org/jira/browse/EMAIL-28 > Project: Commons Email > Issue Type: Bug > Affects Versions: 1.0 > Environment: Operating System: Windows XP > Platform: PC > Reporter: Phil Bretherton > Fix For: 1.1 > > > I have three problems that are probably related. The results are using Mozilla > Thunderbird. > 1. When I send an HtmlEmail with attachments, embedded images, an HTML body > and > an alternative text body both the alternative text and the HTML are displayed. > 2. When I send an HtmlEmail with embedded images, no attachments, an HTML body > and I do not provide an alternative text body, the HTML body is not displayed. > 3. When I send an HtmlEmail with attachments, embedded images, an HTML body > and > I do not provide an alternative text, everything works almost fine. The only > problem is that when the SMTP server is sending emails outside its domain it > adds a disclaimer. The addition of this disclaimer means that only the > disclaimer is displayed. This does not happend when using Javamail. > Below is the class that I used for my tests. > import java.net.MalformedURLException; > import java.net.URL; > import org.apache.commons.mail.EmailAttachment; > import org.apache.commons.mail.EmailException; > import org.apache.commons.mail.HtmlEmail; > public class CommonsEmailTest { > /** > * @param args > */ > public static void main(String[] args) { > try { > testHtmlEmailWithAttachmentsAndEmbeddedImages(); > testHtmlEmailWithoutAttachmentsOrText(); > testHtmlEmailWithAttachmentsAndEmbeddedImagesNoText(); > } catch (MalformedURLException e) { > e.printStackTrace(); > } catch (EmailException e) { > e.printStackTrace(); > } > } > > /** > * This method sends an HTML email with attachments, embedded images, > * an HTML body and an alternative text body. The result is that both > * the HTML and the text are displayed. > * > * @throws EmailException > * @throws MalformedURLException > */ > public static void testHtmlEmailWithAttachmentsAndEmbeddedImages() > throws > EmailException, MalformedURLException { > > // Create the email message > HtmlEmail email = new HtmlEmail(); > email.setHostName("smtp.capgemini.fr"); > email.addTo("[EMAIL PROTECTED]", "You"); > email.setFrom("[EMAIL PROTECTED]", "Me"); > email.setSubject("Test email with inline image and attachment"); > > // Create the attachment > EmailAttachment attachment = new EmailAttachment(); > attachment.setPath("D:/temp/mypic.jpg"); > attachment.setDisposition(EmailAttachment.ATTACHMENT); > attachment.setDescription("A picture"); > attachment.setName("Thingy"); > > email.attach(attachment); > // embed the image and get the content id > URL url = new > URL("http://www.apache.org/images/asf_logo_wide.gif"); > String cid = email.embed(url, "Apache logo"); > // set the html message > email.setHtmlMsg("<html>The apache logo - <img > src=\"cid:"+cid+"\"></html>"); > // set the alternative message > email.setTextMsg("Your email client does not support HTML > messages"); > // send the email > email.send(); > } > /** > * This method sends an HTML email with embedded images, > * an HTML body and no alternative text body. The result is that both > * the HTML is not displayed. > * > * @throws EmailException > * @throws MalformedURLException > */ > public static void testHtmlEmailWithoutAttachmentsOrText() throws > EmailException, MalformedURLException { > > // Create the email message > HtmlEmail email = new HtmlEmail(); > email.setHostName("smtp.capgemini.fr"); > email.addTo("[EMAIL PROTECTED]", "You"); > email.setFrom("[EMAIL PROTECTED]", "Me"); > email.setSubject("Test email with inline image and no > alternative text"); > > // embed the image and get the content id > URL url = new > URL("http://www.apache.org/images/asf_logo_wide.gif"); > String cid = email.embed(url, "Apache logo"); > // set the html message > email.setHtmlMsg("<html>The apache logo - <img > src=\"cid:"+cid+"\"></html>"); > // send the email > email.send(); > } > /** > * This method sends an HTML email with attachments, embedded images, > * an HTML body and no alternative text body. The normal result is that > * everything is displayed as expected. However, if the SMTP server > * adds a disclaimer, the disclaimer is the only thing displayed. > * > * @throws EmailException > * @throws MalformedURLException > */ > public static void > testHtmlEmailWithAttachmentsAndEmbeddedImagesNoText() throws > EmailException, MalformedURLException { > > // Create the email message > HtmlEmail email = new HtmlEmail(); > email.setHostName("smtp.capgemini.fr"); > email.addTo("[EMAIL PROTECTED]", "You"); > email.setFrom("[EMAIL PROTECTED]", "Me"); > email.setSubject("Test email with disclaimer"); > > // Create the attachment > EmailAttachment attachment = new EmailAttachment(); > attachment.setPath("D:/temp/mypic.jpg"); > attachment.setDisposition(EmailAttachment.ATTACHMENT); > attachment.setDescription("A picture"); > attachment.setName("Thingy"); > > email.attach(attachment); > // embed the image and get the content id > URL url = new > URL("http://www.apache.org/images/asf_logo_wide.gif"); > String cid = email.embed(url, "Apache logo"); > // set the html message > email.setHtmlMsg("<html>The apache logo - <img > src=\"cid:"+cid+"\"></html>"); > // send the email > email.send(); > } > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]