1 package info.magnolia.cms.mail; 2 3 import info.magnolia.cms.mail.templates.MailAttachment; 4 import info.magnolia.cms.mail.templates.MgnlEmail; 5 import info.magnolia.cms.mail.templates.impl.HtmlEmail; 6 7 import java.io.File ; 8 import java.util.ArrayList ; 9 import java.util.HashMap ; 10 import java.util.Iterator ; 11 12 import org.subethamail.wiser.WiserMessage; 13 14 15 18 public class HtmlMailTest extends AbstractMailTest { 19 20 public void testHtmlMail() throws Exception { 21 MgnlEmail email = factory.getEmailFromType(MailConstants.MAIL_TEMPLATE_HTML); 22 String subject = "test html email"; 23 email.setSubject(subject); 24 email.setBody("<h1>Helloniko</h1>", null); 25 email.setToList(TEST_RECIPIENT); 26 email.setFrom(TEST_SENDER); 27 28 handler.prepareAndSendMail(email); 29 30 assertTrue(wiser.getMessages().size() == 1); 31 Iterator emailIter = wiser.getMessages().iterator(); 32 WiserMessage message = (WiserMessage) emailIter.next(); 33 assertTrue(message.getMimeMessage().getSubject().equals(subject)); 34 } 35 36 public void testHtmlMailWithImageFile() throws Exception { 37 MgnlEmail email = factory.getEmailFromType(MailConstants.MAIL_TEMPLATE_HTML); 38 email.addAttachment(new MailAttachment(new File (getResourcePath(TEST_FILE_JPG)).toURL(), "att")); 39 email.setBody("<h1>Helloniko</h1><img SRC=\"cid:att\"/>", null); 40 String subject = "test html email"; 41 email.setSubject(subject); 42 email.setToList(TEST_RECIPIENT); 43 email.setFrom(TEST_SENDER); 44 45 handler.prepareAndSendMail(email); 46 47 assertTrue(wiser.getMessages().size() == 1); 48 Iterator emailIter = wiser.getMessages().iterator(); 49 WiserMessage message = (WiserMessage) emailIter.next(); 50 assertTrue(message.getMimeMessage().getSubject().equals(subject)); 51 } 52 53 public void testHtmlMailWithTwoEmbeddedContent() throws Exception { 54 MgnlEmail email = factory.getEmailFromType(MailConstants.MAIL_TEMPLATE_HTML); 55 ArrayList attach = new ArrayList (); 56 attach.add(new MailAttachment(new File (getResourcePath(TEST_FILE_JPG)).toURL(), "att1")); 57 attach.add(new MailAttachment(new File (getResourcePath(TEST_FILE_PDF)).toURL(), "att2")); 58 HashMap param = new HashMap (1); 59 param.put(HtmlEmail.MAIL_ATTACHMENT, attach); 60 String subject = "test html email"; 61 email.setSubject(subject); 62 email.setBody("<h1>Helloniko</h1><img SRC=\"cid:att1\"/><img SRC=\"cid:att2\"/>", param); 63 email.setToList(TEST_RECIPIENT); 64 email.setFrom(TEST_SENDER); 65 66 handler.prepareAndSendMail(email); 67 68 assertTrue(wiser.getMessages().size() == 1); 69 Iterator emailIter = wiser.getMessages().iterator(); 70 WiserMessage message = (WiserMessage) emailIter.next(); 71 assertTrue(message.getMimeMessage().getSubject().equals(subject)); 72 } 73 74 public void testHtmlMailWithPdf() throws Exception { 75 MgnlEmail email = factory.getEmailFromType(MailConstants.MAIL_TEMPLATE_HTML); 76 String subject = "test html email"; 77 email.setSubject(subject); 78 email.setBody("<h1>Helloniko in pdf</h1>", new HashMap (0)); 79 email.addAttachment(new MailAttachment(new File (getResourcePath(TEST_FILE_PDF)).toURL(), "att1")); 80 email.setToList(TEST_RECIPIENT); 81 email.setFrom(TEST_SENDER); 82 83 handler.prepareAndSendMail(email); 84 85 assertTrue(wiser.getMessages().size() == 1); 86 Iterator emailIter = wiser.getMessages().iterator(); 87 WiserMessage message = (WiserMessage) emailIter.next(); 88 assertTrue(message.getMimeMessage().getSubject().equals(subject)); 89 } 90 91 } 92 | Popular Tags |