From 36aa623f0c9e18f189bc13e3e4adb39107597646 Mon Sep 17 00:00:00 2001 From: Cody Lerum Date: Thu, 3 Mar 2011 18:24:06 -0700 Subject: [PATCH] drop ClassPathEmailAttachment and ClassPathTemplate. Use InputStream versions with ResourceProvider.loadResourceStream --- ...ailAttachment.java => BaseAttachment.java} | 8 +- .../attachments/ClassPathEmailAttachment.java | 49 ---- .../seam/mail/attachments/FileAttachment.java | 45 ++++ ...chment.java => InputStreamAttachment.java} | 6 +- ...mailAttachment.java => URLAttachment.java} | 6 +- .../seam/mail/core/FileEmailAttachment.java | 4 +- .../jboss/seam/mail/core/MailMessageImpl.java | 4 +- .../mail/templating/ClassPathTemplate.java | 63 ----- ...Template.java => InputStreamTemplate.java} | 10 +- .../seam/mail/templating/MailContext.java | 54 ++++ .../jboss/seam/mail/util/MailTestUtil.java | 55 ++++ .../org/jboss/seam/mail/util/MailUtility.java | 253 ++++++++++++++++++ .../org/jboss/seam/mail/example/SendMail.java | 30 ++- .../seam/mail/FreeMarkerMailMessageTest.java | 30 ++- .../org/jboss/seam/mail/MailMessageTest.java | 22 +- .../seam/mail/VelocityMailMessageTest.java | 31 ++- .../freemarker/FreeMarkerMailMessageImpl.java | 4 +- .../velocity/VelocityMailMessageImpl.java | 4 +- 18 files changed, 501 insertions(+), 177 deletions(-) rename core/impl/src/main/java/org/jboss/seam/mail/attachments/{BaseEmailAttachment.java => BaseAttachment.java} (84%) delete mode 100644 core/impl/src/main/java/org/jboss/seam/mail/attachments/ClassPathEmailAttachment.java create mode 100644 core/impl/src/main/java/org/jboss/seam/mail/attachments/FileAttachment.java rename core/impl/src/main/java/org/jboss/seam/mail/attachments/{InputStreamEmailAttachment.java => InputStreamAttachment.java} (68%) rename core/impl/src/main/java/org/jboss/seam/mail/attachments/{URLEmailAttachment.java => URLAttachment.java} (78%) delete mode 100644 core/impl/src/main/java/org/jboss/seam/mail/templating/ClassPathTemplate.java rename core/impl/src/main/java/org/jboss/seam/mail/templating/{InputStreamMailTemplate.java => InputStreamTemplate.java} (78%) create mode 100644 core/impl/src/main/java/org/jboss/seam/mail/templating/MailContext.java create mode 100644 core/impl/src/main/java/org/jboss/seam/mail/util/MailTestUtil.java create mode 100644 core/impl/src/main/java/org/jboss/seam/mail/util/MailUtility.java diff --git a/core/impl/src/main/java/org/jboss/seam/mail/attachments/BaseEmailAttachment.java b/core/impl/src/main/java/org/jboss/seam/mail/attachments/BaseAttachment.java similarity index 84% rename from core/impl/src/main/java/org/jboss/seam/mail/attachments/BaseEmailAttachment.java rename to core/impl/src/main/java/org/jboss/seam/mail/attachments/BaseAttachment.java index 229fa89..05ff8cd 100644 --- a/core/impl/src/main/java/org/jboss/seam/mail/attachments/BaseEmailAttachment.java +++ b/core/impl/src/main/java/org/jboss/seam/mail/attachments/BaseAttachment.java @@ -31,7 +31,7 @@ * @author Cody Lerum * */ -public class BaseEmailAttachment extends BeanManagerAware implements EmailAttachment +public class BaseAttachment extends BeanManagerAware implements EmailAttachment { private String contentId; private String fileName; @@ -40,7 +40,7 @@ public class BaseEmailAttachment extends BeanManagerAware implements EmailAttach private Collection
headers = new ArrayList
(); private byte[] bytes; - public BaseEmailAttachment(String fileName, String mimeType, ContentDisposition contentDisposition, byte[] bytes) + public BaseAttachment(String fileName, String mimeType, ContentDisposition contentDisposition, byte[] bytes) { this(); this.fileName = fileName; @@ -49,13 +49,13 @@ public BaseEmailAttachment(String fileName, String mimeType, ContentDisposition this.bytes = bytes; } - public BaseEmailAttachment(String fileName, String mimeType, ContentDisposition contentDisposition, byte[] bytes, String contentClass) + public BaseAttachment(String fileName, String mimeType, ContentDisposition contentDisposition, byte[] bytes, String contentClass) { this(fileName, mimeType, contentDisposition, bytes); this.addHeader(new Header("Content-Class", contentClass)); } - public BaseEmailAttachment() + public BaseAttachment() { this.contentId = UUID.randomUUID().toString(); } diff --git a/core/impl/src/main/java/org/jboss/seam/mail/attachments/ClassPathEmailAttachment.java b/core/impl/src/main/java/org/jboss/seam/mail/attachments/ClassPathEmailAttachment.java deleted file mode 100644 index bb0dd7e..0000000 --- a/core/impl/src/main/java/org/jboss/seam/mail/attachments/ClassPathEmailAttachment.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.jboss.seam.mail.attachments; - -import java.io.IOException; -import java.io.InputStream; - -import javax.enterprise.inject.spi.Bean; -import javax.enterprise.inject.spi.BeanManager; - -import org.jboss.seam.mail.core.AttachmentException; -import org.jboss.seam.mail.core.Header; -import org.jboss.seam.mail.core.enumurations.ContentDisposition; -import org.jboss.seam.solder.resourceLoader.ResourceProvider; - -import com.google.common.io.ByteStreams; - -public class ClassPathEmailAttachment extends BaseEmailAttachment -{ - public ClassPathEmailAttachment(String fileName, String mimeType, ContentDisposition contentDisposition) - { - super(); - - try - { - super.setFileName(fileName); - super.setMimeType(mimeType); - super.setContentDisposition(contentDisposition); - super.setBytes(ByteStreams.toByteArray(inputStreamFromClassPath(fileName))); - } - catch (IOException e) - { - throw new AttachmentException("Wasn't able to create email attachment from Class Path file: " + fileName, e); - } - } - - public ClassPathEmailAttachment(String fileName, String mimeType, ContentDisposition contentDisposition, String contentClass) - { - this(fileName, mimeType, contentDisposition); - super.addHeader(new Header("Content-Class", contentClass)); - } - - private InputStream inputStreamFromClassPath(String fileName) - { - BeanManager bm = getBeanManager(); - Bean bean = bm.resolve(bm.getBeans(ResourceProvider.class)); - ResourceProvider resourceProvider = (ResourceProvider) bm.getReference(bean, bean.getBeanClass(), bm.createCreationalContext(bean)); - return resourceProvider.loadResourceStream(fileName); - } - -} diff --git a/core/impl/src/main/java/org/jboss/seam/mail/attachments/FileAttachment.java b/core/impl/src/main/java/org/jboss/seam/mail/attachments/FileAttachment.java new file mode 100644 index 0000000..1d0256e --- /dev/null +++ b/core/impl/src/main/java/org/jboss/seam/mail/attachments/FileAttachment.java @@ -0,0 +1,45 @@ +package org.jboss.seam.mail.attachments; + +import java.io.File; +import java.io.IOException; + +import javax.activation.FileDataSource; + +import org.jboss.seam.mail.core.AttachmentException; +import org.jboss.seam.mail.core.Header; +import org.jboss.seam.mail.core.enumurations.ContentDisposition; + +import com.google.common.io.Files; + +/** + * + * @author Cody Lerum + * + */ +public class FileAttachment extends BaseAttachment +{ + public FileAttachment(File file, ContentDisposition contentDisposition) + { + super(); + + FileDataSource fds = new FileDataSource(file); + + try + { + super.setFileName(fds.getName()); + super.setMimeType(fds.getContentType()); + super.setContentDisposition(contentDisposition); + super.setBytes(Files.toByteArray(file)); + } + catch (IOException e) + { + throw new AttachmentException("Wasn't able to create email attachment from File: " + file.getName(), e); + } + } + + public FileAttachment(File file, ContentDisposition contentDisposition, String contentClass) + { + this(file, contentDisposition); + super.addHeader(new Header("Content-Class", contentClass)); + } +} diff --git a/core/impl/src/main/java/org/jboss/seam/mail/attachments/InputStreamEmailAttachment.java b/core/impl/src/main/java/org/jboss/seam/mail/attachments/InputStreamAttachment.java similarity index 68% rename from core/impl/src/main/java/org/jboss/seam/mail/attachments/InputStreamEmailAttachment.java rename to core/impl/src/main/java/org/jboss/seam/mail/attachments/InputStreamAttachment.java index 6b9b148..09eef46 100644 --- a/core/impl/src/main/java/org/jboss/seam/mail/attachments/InputStreamEmailAttachment.java +++ b/core/impl/src/main/java/org/jboss/seam/mail/attachments/InputStreamAttachment.java @@ -14,9 +14,9 @@ * @author Cody Lerum * */ -public class InputStreamEmailAttachment extends BaseEmailAttachment +public class InputStreamAttachment extends BaseAttachment { - public InputStreamEmailAttachment(InputStream inputStream, String fileName, String mimeType, ContentDisposition contentDisposition) + public InputStreamAttachment(InputStream inputStream, String fileName, String mimeType, ContentDisposition contentDisposition) { super(); @@ -33,7 +33,7 @@ public InputStreamEmailAttachment(InputStream inputStream, String fileName, Stri } } - public InputStreamEmailAttachment(InputStream inputStream, String fileName, String mimeType, ContentDisposition contentDisposition, String contentClass) + public InputStreamAttachment(InputStream inputStream, String fileName, String mimeType, ContentDisposition contentDisposition, String contentClass) { this(inputStream, fileName, mimeType, contentDisposition); super.addHeader(new Header("Content-Class", contentClass)); diff --git a/core/impl/src/main/java/org/jboss/seam/mail/attachments/URLEmailAttachment.java b/core/impl/src/main/java/org/jboss/seam/mail/attachments/URLAttachment.java similarity index 78% rename from core/impl/src/main/java/org/jboss/seam/mail/attachments/URLEmailAttachment.java rename to core/impl/src/main/java/org/jboss/seam/mail/attachments/URLAttachment.java index cf959c3..960f7d1 100644 --- a/core/impl/src/main/java/org/jboss/seam/mail/attachments/URLEmailAttachment.java +++ b/core/impl/src/main/java/org/jboss/seam/mail/attachments/URLAttachment.java @@ -10,9 +10,9 @@ import org.jboss.seam.mail.core.Header; import org.jboss.seam.mail.core.enumurations.ContentDisposition; -public class URLEmailAttachment extends BaseEmailAttachment +public class URLAttachment extends BaseAttachment { - public URLEmailAttachment(String url, String fileName, ContentDisposition contentDisposition) + public URLAttachment(String url, String fileName, ContentDisposition contentDisposition) { super(); @@ -40,7 +40,7 @@ public URLEmailAttachment(String url, String fileName, ContentDisposition conten } } - public URLEmailAttachment(String url, String fileName, ContentDisposition contentDisposition, String contentClass) + public URLAttachment(String url, String fileName, ContentDisposition contentDisposition, String contentClass) { this(url, fileName, contentDisposition); super.addHeader(new Header("Content-Class", contentClass)); diff --git a/core/impl/src/main/java/org/jboss/seam/mail/core/FileEmailAttachment.java b/core/impl/src/main/java/org/jboss/seam/mail/core/FileEmailAttachment.java index 5dcca81..38ffeca 100644 --- a/core/impl/src/main/java/org/jboss/seam/mail/core/FileEmailAttachment.java +++ b/core/impl/src/main/java/org/jboss/seam/mail/core/FileEmailAttachment.java @@ -5,7 +5,7 @@ import javax.activation.FileDataSource; -import org.jboss.seam.mail.attachments.BaseEmailAttachment; +import org.jboss.seam.mail.attachments.BaseAttachment; import org.jboss.seam.mail.core.enumurations.ContentDisposition; import com.google.common.io.Files; @@ -15,7 +15,7 @@ * @author Cody Lerum * */ -public class FileEmailAttachment extends BaseEmailAttachment +public class FileEmailAttachment extends BaseAttachment { public FileEmailAttachment(File file, ContentDisposition contentDisposition) { diff --git a/core/impl/src/main/java/org/jboss/seam/mail/core/MailMessageImpl.java b/core/impl/src/main/java/org/jboss/seam/mail/core/MailMessageImpl.java index 719b559..ad514e6 100644 --- a/core/impl/src/main/java/org/jboss/seam/mail/core/MailMessageImpl.java +++ b/core/impl/src/main/java/org/jboss/seam/mail/core/MailMessageImpl.java @@ -25,7 +25,7 @@ import javax.mail.internet.InternetAddress; import org.jboss.seam.mail.api.MailMessage; -import org.jboss.seam.mail.attachments.BaseEmailAttachment; +import org.jboss.seam.mail.attachments.BaseAttachment; import org.jboss.seam.mail.core.enumurations.ContentDisposition; import org.jboss.seam.mail.core.enumurations.ContentType; import org.jboss.seam.mail.core.enumurations.EmailMessageType; @@ -278,7 +278,7 @@ public MailMessage iCal(String html, byte[] bytes) { emailMessage.setType(EmailMessageType.INVITE_ICAL); emailMessage.setHtmlBody(html); - emailMessage.addAttachment(new BaseEmailAttachment(null, "text/calendar;method=CANCEL", ContentDisposition.INLINE, bytes, "urn:content-classes:calendarmessage")); + emailMessage.addAttachment(new BaseAttachment(null, "text/calendar;method=CANCEL", ContentDisposition.INLINE, bytes, "urn:content-classes:calendarmessage")); return this; } diff --git a/core/impl/src/main/java/org/jboss/seam/mail/templating/ClassPathTemplate.java b/core/impl/src/main/java/org/jboss/seam/mail/templating/ClassPathTemplate.java deleted file mode 100644 index 154ce2f..0000000 --- a/core/impl/src/main/java/org/jboss/seam/mail/templating/ClassPathTemplate.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2011, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jboss.seam.mail.templating; - -import java.io.InputStream; - -import javax.enterprise.inject.spi.Bean; -import javax.enterprise.inject.spi.BeanManager; - -import org.jboss.seam.mail.core.MailTemplate; -import org.jboss.seam.solder.beanManager.BeanManagerAware; -import org.jboss.seam.solder.resourceLoader.ResourceProvider; - -/** - * - * @author Cody Lerum - * - */ -public class ClassPathTemplate extends BeanManagerAware implements MailTemplate -{ - private String templateName; - private String fileName; - - public ClassPathTemplate(String fileName) - { - this.templateName = fileName; - this.fileName = fileName; - } - - public ClassPathTemplate(String fileName, String templateName) - { - this.templateName = templateName; - this.fileName = fileName; - } - - public InputStream getInputStream() - { - BeanManager bm = getBeanManager(); - Bean bean = bm.resolve(bm.getBeans(ResourceProvider.class)); - ResourceProvider resourceProvider = (ResourceProvider) bm.getReference(bean, bean.getBeanClass(), bm.createCreationalContext(bean)); - return resourceProvider.loadResourceStream(fileName); - } - - public String getTemplateName() - { - return templateName; - } -} diff --git a/core/impl/src/main/java/org/jboss/seam/mail/templating/InputStreamMailTemplate.java b/core/impl/src/main/java/org/jboss/seam/mail/templating/InputStreamTemplate.java similarity index 78% rename from core/impl/src/main/java/org/jboss/seam/mail/templating/InputStreamMailTemplate.java rename to core/impl/src/main/java/org/jboss/seam/mail/templating/InputStreamTemplate.java index 1db79ed..b7fea2f 100644 --- a/core/impl/src/main/java/org/jboss/seam/mail/templating/InputStreamMailTemplate.java +++ b/core/impl/src/main/java/org/jboss/seam/mail/templating/InputStreamTemplate.java @@ -26,16 +26,22 @@ * @author Cody Lerum * */ -public class InputStreamMailTemplate implements MailTemplate +public class InputStreamTemplate implements MailTemplate { private String templateName; private InputStream inputStream; - public InputStreamMailTemplate(InputStream inputStream, String templateName) + public InputStreamTemplate(InputStream inputStream, String templateName) { this.templateName = templateName; this.inputStream = inputStream; } + + public InputStreamTemplate(InputStream inputStream) + { + this.templateName = "default"; + this.inputStream = inputStream; + } public String getTemplateName() { diff --git a/core/impl/src/main/java/org/jboss/seam/mail/templating/MailContext.java b/core/impl/src/main/java/org/jboss/seam/mail/templating/MailContext.java new file mode 100644 index 0000000..bd53e85 --- /dev/null +++ b/core/impl/src/main/java/org/jboss/seam/mail/templating/MailContext.java @@ -0,0 +1,54 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011, Red Hat, Inc., and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.seam.mail.templating; + +import java.util.Map; + +import org.jboss.seam.mail.core.EmailAttachment; + +/** + * + * @author Cody Lerum + * + */ +public class MailContext +{ + + private Map attachments; + + public MailContext(Map attachments) + { + this.attachments = attachments; + } + + public String insert(String fileName) + { + EmailAttachment attachment = null; + + attachment = attachments.get(fileName); + + if (attachment == null) + { + throw new RuntimeException("Unable to find attachment: " + fileName); + } + else + { + return "cid:" + attachment.getContentId(); + } + } +} diff --git a/core/impl/src/main/java/org/jboss/seam/mail/util/MailTestUtil.java b/core/impl/src/main/java/org/jboss/seam/mail/util/MailTestUtil.java new file mode 100644 index 0000000..07f99e2 --- /dev/null +++ b/core/impl/src/main/java/org/jboss/seam/mail/util/MailTestUtil.java @@ -0,0 +1,55 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011, Red Hat, Inc., and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.seam.mail.util; + +import java.io.IOException; +import java.io.InputStreamReader; + +import javax.mail.BodyPart; +import javax.mail.MessagingException; +import javax.mail.internet.MimeMultipart; + +import com.google.common.io.CharStreams; + +/** + * + * @author Cody Lerum + * + */ +public class MailTestUtil +{ + public static String getAddressHeader(String address) + { + return address; + } + + public static String getAddressHeader(String name, String address) + { + return name + " <" + address + ">"; + } + + public static String getStringContent(MimeMultipart mmp, int index) throws IOException, MessagingException + { + return getStringContent(mmp.getBodyPart(index)); + } + + public static String getStringContent(BodyPart bodyPart) throws IOException, MessagingException + { + return CharStreams.toString(new InputStreamReader(bodyPart.getInputStream())); + } +} diff --git a/core/impl/src/main/java/org/jboss/seam/mail/util/MailUtility.java b/core/impl/src/main/java/org/jboss/seam/mail/util/MailUtility.java new file mode 100644 index 0000000..b59ba16 --- /dev/null +++ b/core/impl/src/main/java/org/jboss/seam/mail/util/MailUtility.java @@ -0,0 +1,253 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2011, Red Hat, Inc., and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jboss.seam.mail.util; + +import java.io.UnsupportedEncodingException; +import java.net.UnknownHostException; +import java.util.Collection; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import javax.mail.MessagingException; +import javax.mail.Session; +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; + +import org.jboss.seam.mail.core.BaseMailMessage; +import org.jboss.seam.mail.core.EmailContact; +import org.jboss.seam.mail.core.EmailMessage; +import org.jboss.seam.mail.core.InvalidAddressException; +import org.jboss.seam.mail.core.MailConfig; +import org.jboss.seam.mail.core.MailSessionAuthenticator; +import org.jboss.seam.mail.core.SendFailedException; +import org.jboss.seam.mail.core.enumurations.EmailMessageType; +import org.jboss.seam.mail.core.enumurations.RecipientType; + +/** + * + * @author Cody Lerum + * + */ +public class MailUtility +{ + public static InternetAddress internetAddress(String address) throws InvalidAddressException + { + try + { + return new InternetAddress(address); + } + catch (AddressException e) + { + throw new InvalidAddressException(e); + } + } + + public static InternetAddress internetAddress(String address, String name) throws InvalidAddressException + { + InternetAddress internetAddress; + try + { + internetAddress = new InternetAddress(address); + internetAddress.setPersonal(name); + return internetAddress; + } + catch (AddressException e) + { + throw new InvalidAddressException(e); + } + catch (UnsupportedEncodingException e) + { + throw new InvalidAddressException(e); + } + } + + public static InternetAddress internetAddress(EmailContact emailContact) throws InvalidAddressException + { + if (Strings.isNullOrBlank(emailContact.getName())) + { + return MailUtility.internetAddress(emailContact.getAddress()); + } + else + { + return MailUtility.internetAddress(emailContact.getAddress(), emailContact.getName()); + } + } + + public static Collection internetAddress(Collection emailContacts) throws InvalidAddressException + { + Set internetAddresses = new HashSet(); + + for (EmailContact ec : emailContacts) + { + internetAddresses.add(MailUtility.internetAddress(ec)); + } + + return internetAddresses; + } + + public static InternetAddress[] getInternetAddressses(InternetAddress emaiAddress) + { + InternetAddress[] internetAddresses = { emaiAddress }; + + return internetAddresses; + } + + public static InternetAddress[] getInternetAddressses(Collection recipients) + { + InternetAddress[] result = new InternetAddress[recipients.size()]; + recipients.toArray(result); + return result; + } + + public static String getHostName() + { + try + { + java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost(); + return localMachine.getHostName(); + } + catch (UnknownHostException e) + { + return "localhost"; + } + } + + public static Session buildMailSession(MailConfig mailConfig) + { + Session session; + + Properties props = new Properties(); + + if (mailConfig.isValid()) + { + props.put("mail.smtp.host", mailConfig.getServerHost()); + props.put("mail.smtp.port", mailConfig.getServerPort()); + props.put("mail.smtp.starttls.enable", mailConfig.isEnableTls()); + props.put("mail.smtp.starttls.required", mailConfig.isRequireTls()); + props.put("mail.smtp.ssl.enable", mailConfig.isEnableSsl()); + props.put("mail.smtp.auth", mailConfig.isAuth()); + } + else + { + throw new RuntimeException("ServerHost and ServerPort must be set in MailConfig"); + } + + if (!Strings.isNullOrBlank(mailConfig.getDomainName())) + { + props.put("mail.seam.domainName", mailConfig.getDomainName()); + } + + if (mailConfig.getUsername() != null && mailConfig.getUsername().length() != 0 && mailConfig.getPassword() != null && mailConfig.getPassword().length() != 0) + { + MailSessionAuthenticator authenticator = new MailSessionAuthenticator(mailConfig.getUsername(), mailConfig.getPassword()); + + session = Session.getInstance(props, authenticator); + } + else + { + session = Session.getInstance(props, null); + } + return session; + } + + public static String headerStripper(String header) + { + if (!Strings.isNullOrBlank(header)) + { + String s = header.trim(); + + if (s.matches("^<.*>$")) + { + return header.substring(1, header.length() - 1); + } + else + { + return header; + } + } + else + { + return header; + } + } + + public static void send(EmailMessage e, Session session) throws SendFailedException + { + BaseMailMessage b = new BaseMailMessage(session, e.getRootContentType()); + + if (!Strings.isNullOrBlank(e.getMessageId())) + { + b.setMessageID(e.getMessageId()); + } + + b.setFrom(e.getFromAddresses()); + b.addRecipients(RecipientType.TO, e.getToAddresses()); + b.addRecipients(RecipientType.CC, e.getCcAddresses()); + b.addRecipients(RecipientType.BCC, e.getBccAddresses()); + b.setReplyTo(e.getReplyToAddresses()); + b.addDeliveryRecieptAddresses(e.getDeliveryReceiptAddresses()); + b.addReadRecieptAddresses(e.getReadReceiptAddresses()); + b.setImportance(e.getImportance()); + b.addHeaders(e.getHeaders()); + + if (e.getSubject() != null) + { + b.setSubject(e.getSubject()); + } + + if (e.getType() == EmailMessageType.STANDARD) + { + + if (e.getHtmlBody() != null && e.getTextBody() != null) + { + b.setHTMLTextAlt(e.getHtmlBody(), e.getTextBody()); + } + else if (e.getTextBody() != null) + { + b.setText(e.getTextBody()); + } + else if (e.getHtmlBody() != null) + { + b.setHTML(e.getHtmlBody()); + } + + b.addAttachments(e.getAttachments()); + } + else if (e.getType() == EmailMessageType.INVITE_ICAL) + { + b.setHTMLNotRelated(e.getHtmlBody()); + b.addAttachments(e.getAttachments()); + } + else + { + throw new RuntimeException("Unsupported Message Type: " + e.getType()); + } + b.send(); + + try + { + e.setMessageId(null); + e.setLastMessageId(MailUtility.headerStripper(b.getFinalizedMessage().getMessageID())); + } + catch (MessagingException e1) + { + throw new RuntimeException("Unable to read Message-ID from sent message"); + } + } +} diff --git a/examples/sendmail/src/main/java/org/jboss/seam/mail/example/SendMail.java b/examples/sendmail/src/main/java/org/jboss/seam/mail/example/SendMail.java index bdd62c8..7240239 100644 --- a/examples/sendmail/src/main/java/org/jboss/seam/mail/example/SendMail.java +++ b/examples/sendmail/src/main/java/org/jboss/seam/mail/example/SendMail.java @@ -25,13 +25,14 @@ import javax.mail.Session; import org.jboss.seam.mail.api.MailMessage; -import org.jboss.seam.mail.attachments.ClassPathEmailAttachment; -import org.jboss.seam.mail.attachments.URLEmailAttachment; +import org.jboss.seam.mail.attachments.InputStreamAttachment; +import org.jboss.seam.mail.attachments.URLAttachment; import org.jboss.seam.mail.core.enumurations.ContentDisposition; import org.jboss.seam.mail.core.enumurations.MessagePriority; -import org.jboss.seam.mail.templating.ClassPathTemplate; import org.jboss.seam.mail.templating.FreeMarkerMailMessage; +import org.jboss.seam.mail.templating.InputStreamTemplate; import org.jboss.seam.mail.templating.VelocityMailMessage; +import org.jboss.seam.solder.resourceLoader.ResourceProvider; /** * * @author Cody Lerum @@ -51,6 +52,9 @@ public class SendMail @Inject private Instance freeMarkerMailMessage; + @Inject + private ResourceProvider resourceProvider; + @Inject private Instance session; @@ -73,11 +77,11 @@ public void sendHTMLFreeMarker() throws MalformedURLException .from("seam@test.test", "Seam Framework") .to(person) .subject("HTML Message from Seam Mail - " + java.util.UUID.randomUUID().toString()) - .bodyHtml(new ClassPathTemplate("template.html.freemarker")) + .bodyHtml(new InputStreamTemplate(resourceProvider.loadResourceStream("template.html.freemarker"))) .put("person", person) .put("version", "Seam 3") .importance(MessagePriority.HIGH) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(session.get()); } @@ -89,12 +93,12 @@ public void sendHTMLwithAlternativeFreeMarker() throws MalformedURLException .subject("HTML+Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString()) .put("person", person) .put("version", "Seam 3") - .bodyHtmlTextAlt(new ClassPathTemplate("template.html.freemarker"), new ClassPathTemplate("template.text.freemarker")) + .bodyHtmlTextAlt(new InputStreamTemplate(resourceProvider.loadResourceStream("template.html.freemarker")), new InputStreamTemplate(resourceProvider.loadResourceStream("template.text.freemarker"))) .importance(MessagePriority.LOW) .deliveryReceipt("seam@jboss.org") .readReceipt("seam@jboss.org") - .addAttachment(new ClassPathEmailAttachment("template.html.freemarker", "text/html", ContentDisposition.ATTACHMENT)) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) + .addAttachment(new InputStreamAttachment(resourceProvider.loadResourceStream("template.html.freemarker"),"template.html.freemarker", "text/html", ContentDisposition.ATTACHMENT)) + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(session.get()); } @@ -104,10 +108,10 @@ public void sendHTMLVelocity() throws MalformedURLException .from("seam@test.test", "Seam Framework") .to(person) .subject("HTML Message from Seam Mail - " + java.util.UUID.randomUUID().toString()) - .bodyHtml(new ClassPathTemplate("template.html.velocity")) + .bodyHtml(new InputStreamTemplate(resourceProvider.loadResourceStream("template.html.velocity"))) .put("version", "Seam 3") .importance(MessagePriority.HIGH) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(session.get()); } @@ -118,12 +122,12 @@ public void sendHTMLwithAlternativeVelocity() throws MalformedURLException .to(person.getEmail(), person.getName()) .subject("HTML+Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString()) .put("version", "Seam 3") - .bodyHtmlTextAlt(new ClassPathTemplate("template.html.velocity"), new ClassPathTemplate("template.text.velocity")) + .bodyHtmlTextAlt(new InputStreamTemplate(resourceProvider.loadResourceStream("template.html.velocity")), new InputStreamTemplate(resourceProvider.loadResourceStream("template.text.velocity"))) .importance(MessagePriority.LOW) .deliveryReceipt("seam@jboss.org") .readReceipt("seam@jboss.org") - .addAttachment(new ClassPathEmailAttachment("template.html.velocity", "text/html", ContentDisposition.ATTACHMENT)) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) + .addAttachment(new InputStreamAttachment(resourceProvider.loadResourceStream("template.html.velocity"),"template.html.velocity", "text/html", ContentDisposition.ATTACHMENT)) + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(session.get()); } } diff --git a/examples/sendmail/src/test/java/org/jboss/seam/mail/FreeMarkerMailMessageTest.java b/examples/sendmail/src/test/java/org/jboss/seam/mail/FreeMarkerMailMessageTest.java index c7bc0e2..2406676 100644 --- a/examples/sendmail/src/test/java/org/jboss/seam/mail/FreeMarkerMailMessageTest.java +++ b/examples/sendmail/src/test/java/org/jboss/seam/mail/FreeMarkerMailMessageTest.java @@ -33,8 +33,8 @@ import org.jboss.arquillian.api.Deployment; import org.jboss.arquillian.junit.Arquillian; -import org.jboss.seam.mail.attachments.ClassPathEmailAttachment; -import org.jboss.seam.mail.attachments.URLEmailAttachment; +import org.jboss.seam.mail.attachments.InputStreamAttachment; +import org.jboss.seam.mail.attachments.URLAttachment; import org.jboss.seam.mail.core.EmailMessage; import org.jboss.seam.mail.core.MailConfig; import org.jboss.seam.mail.core.MailTestUtil; @@ -43,12 +43,13 @@ import org.jboss.seam.mail.core.enumurations.MessagePriority; import org.jboss.seam.mail.example.Gmail; import org.jboss.seam.mail.example.Person; -import org.jboss.seam.mail.templating.ClassPathTemplate; import org.jboss.seam.mail.templating.FreeMarkerMailMessage; +import org.jboss.seam.mail.templating.InputStreamTemplate; import org.jboss.seam.mail.templating.TextTemplate; import org.jboss.seam.mail.util.EmailAttachmentUtil; import org.jboss.seam.mail.util.MavenArtifactResolver; import org.jboss.seam.mail.util.SMTPAuthenticator; +import org.jboss.seam.solder.resourceLoader.ResourceProvider; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -83,6 +84,9 @@ public static Archive createTestArchive() @Inject private Instance freeMarkerMailMessage; + @Inject + private ResourceProvider resourceProvider; + @Inject private MailConfig mailConfig; @@ -128,7 +132,7 @@ public void testFreeMarkerTextMailMessage() throws MessagingException, IOExcepti .replyTo(replyToAddress) .to(toAddress, toName) .subject(new TextTemplate(subject)) - .bodyText(new ClassPathTemplate("template.text.freemarker")) + .bodyText(new InputStreamTemplate(resourceProvider.loadResourceStream("template.text.freemarker"))) .put("person", person) .put("version", version) .importance(MessagePriority.HIGH) @@ -185,11 +189,11 @@ public void testFreeMarkerHTMLMailMessage() throws MessagingException, IOExcepti .replyTo(replyToAddress, replyToName) .to(person) .subject(subject) - .bodyHtml(new ClassPathTemplate("template.html.freemarker")) + .bodyHtml(new InputStreamTemplate(resourceProvider.loadResourceStream("template.html.freemarker"))) .put("person", person) .put("version", version) .importance(MessagePriority.HIGH) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(session.get()); } finally @@ -252,12 +256,12 @@ public void testFreeMarkerHTMLTextAltMailMessage() throws MessagingException, IO .subject(subject) .put("person", person) .put("version", version) - .bodyHtmlTextAlt(new ClassPathTemplate("template.html.freemarker"), new ClassPathTemplate("template.text.freemarker")) + .bodyHtmlTextAlt(new InputStreamTemplate(resourceProvider.loadResourceStream("template.html.freemarker")), new InputStreamTemplate(resourceProvider.loadResourceStream("template.text.freemarker"))) .importance(MessagePriority.LOW) .deliveryReceipt(fromAddress) .readReceipt("seam.test") - .addAttachment(new ClassPathEmailAttachment("template.html.freemarker", "text/html", ContentDisposition.ATTACHMENT)) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) + .addAttachment(new InputStreamAttachment(resourceProvider.loadResourceStream("template.html.freemarker"), "template.html.freemarker", "text/html", ContentDisposition.ATTACHMENT)) + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(); } finally @@ -329,12 +333,12 @@ public void testSMTPSessionAuthentication() throws MessagingException, Malformed .subject(subject) .put("person", person) .put("version", "Seam 3") - .bodyHtmlTextAlt(new ClassPathTemplate("template.html.freemarker"), new ClassPathTemplate("template.text.freemarker")) + .bodyHtmlTextAlt(new InputStreamTemplate(resourceProvider.loadResourceStream("template.html.freemarker")), new InputStreamTemplate(resourceProvider.loadResourceStream("template.text.freemarker"))) .importance(MessagePriority.LOW) .deliveryReceipt(fromAddress) .readReceipt("seam.test") - .addAttachment(new ClassPathEmailAttachment("template.html.freemarker", "text/html", ContentDisposition.ATTACHMENT)) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) + .addAttachment(new InputStreamAttachment(resourceProvider.loadResourceStream("template.html.freemarker"), "template.html.freemarker", "text/html", ContentDisposition.ATTACHMENT)) + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(gmailSession); } finally @@ -373,7 +377,7 @@ public void testFreeMarkerTextMailMessageSendFailed() .replyTo(replyToAddress) .to(toAddress, toName) .subject(new TextTemplate(subject)) - .bodyText(new ClassPathTemplate("template.text.freemarker")) + .bodyText(new InputStreamTemplate(resourceProvider.loadResourceStream("template.text.freemarker"))) .put("person", person) .put("version", version) .importance(MessagePriority.HIGH) diff --git a/examples/sendmail/src/test/java/org/jboss/seam/mail/MailMessageTest.java b/examples/sendmail/src/test/java/org/jboss/seam/mail/MailMessageTest.java index 8792a4b..3b8893f 100644 --- a/examples/sendmail/src/test/java/org/jboss/seam/mail/MailMessageTest.java +++ b/examples/sendmail/src/test/java/org/jboss/seam/mail/MailMessageTest.java @@ -33,8 +33,8 @@ import org.jboss.arquillian.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.seam.mail.api.MailMessage; -import org.jboss.seam.mail.attachments.ClassPathEmailAttachment; -import org.jboss.seam.mail.attachments.URLEmailAttachment; +import org.jboss.seam.mail.attachments.InputStreamAttachment; +import org.jboss.seam.mail.attachments.URLAttachment; import org.jboss.seam.mail.core.EmailMessage; import org.jboss.seam.mail.core.InvalidAddressException; import org.jboss.seam.mail.core.MailConfig; @@ -45,6 +45,7 @@ import org.jboss.seam.mail.core.enumurations.MessagePriority; import org.jboss.seam.mail.example.Person; import org.jboss.seam.mail.util.MavenArtifactResolver; +import org.jboss.seam.solder.resourceLoader.ResourceProvider; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -63,7 +64,13 @@ public class MailMessageTest @Deployment public static Archive createTestArchive() { - Archive ar = ShrinkWrap.create(WebArchive.class, "test.war").addResource("template.text.velocity", "WEB-INF/classes/template.text.velocity").addPackages(true, MailMessageTest.class.getPackage()).addLibraries(MavenArtifactResolver.resolve("org.jboss.seam.solder:seam-solder:3.0.0.Beta4"), MavenArtifactResolver.resolve("org.subethamail:subethasmtp:3.1.4"), MavenArtifactResolver.resolve("org.apache.velocity:velocity:1.6.4")).addWebResource(EmptyAsset.INSTANCE, "beans.xml"); + Archive ar = ShrinkWrap.create(WebArchive.class, "test.war") + .addResource("template.text.velocity", "WEB-INF/classes/template.text.velocity") + .addPackages(true, MailMessageTest.class.getPackage()) + .addLibraries(MavenArtifactResolver.resolve("org.jboss.seam.solder:seam-solder:3.0.0.Beta4"), + MavenArtifactResolver.resolve("org.subethamail:subethasmtp:3.1.4"), + MavenArtifactResolver.resolve("org.apache.velocity:velocity:1.6.4")) + .addWebResource(EmptyAsset.INSTANCE, "beans.xml"); return ar; } @@ -72,6 +79,9 @@ public static Archive createTestArchive() @Inject private Instance session; + + @Inject + private ResourceProvider resourceProvider; @Inject private MailConfig mailConfig; @@ -173,7 +183,7 @@ public void testHTMLMailMessage() throws MessagingException, IOException .subject(subject) .htmlBody(htmlBody) .importance(MessagePriority.HIGH) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)).send(session.get()); + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)).send(session.get()); } finally { @@ -237,8 +247,8 @@ public void testHTMLTextAltMailMessage() throws MessagingException, IOException .importance(MessagePriority.LOW) .deliveryReceipt(fromAddress) .readReceipt("seam.test") - .addAttachment(new ClassPathEmailAttachment("template.text.velocity", "text/plain", ContentDisposition.ATTACHMENT)) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) + .addAttachment(new InputStreamAttachment(resourceProvider.loadResourceStream("template.text.velocity"), "template.text.velocity", "text/plain", ContentDisposition.ATTACHMENT)) + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(session.get()); } finally diff --git a/examples/sendmail/src/test/java/org/jboss/seam/mail/VelocityMailMessageTest.java b/examples/sendmail/src/test/java/org/jboss/seam/mail/VelocityMailMessageTest.java index 2217f88..ada8692 100644 --- a/examples/sendmail/src/test/java/org/jboss/seam/mail/VelocityMailMessageTest.java +++ b/examples/sendmail/src/test/java/org/jboss/seam/mail/VelocityMailMessageTest.java @@ -33,8 +33,8 @@ import org.jboss.arquillian.api.Deployment; import org.jboss.arquillian.junit.Arquillian; -import org.jboss.seam.mail.attachments.ClassPathEmailAttachment; -import org.jboss.seam.mail.attachments.URLEmailAttachment; +import org.jboss.seam.mail.attachments.InputStreamAttachment; +import org.jboss.seam.mail.attachments.URLAttachment; import org.jboss.seam.mail.core.EmailMessage; import org.jboss.seam.mail.core.MailConfig; import org.jboss.seam.mail.core.MailTestUtil; @@ -43,12 +43,13 @@ import org.jboss.seam.mail.core.enumurations.MessagePriority; import org.jboss.seam.mail.example.Gmail; import org.jboss.seam.mail.example.Person; -import org.jboss.seam.mail.templating.ClassPathTemplate; +import org.jboss.seam.mail.templating.InputStreamTemplate; import org.jboss.seam.mail.templating.TextTemplate; import org.jboss.seam.mail.templating.VelocityMailMessage; import org.jboss.seam.mail.util.EmailAttachmentUtil; import org.jboss.seam.mail.util.MavenArtifactResolver; import org.jboss.seam.mail.util.SMTPAuthenticator; +import org.jboss.seam.solder.resourceLoader.ResourceProvider; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; @@ -77,12 +78,16 @@ public static Archive createTestArchive() MavenArtifactResolver.resolve("org.apache.velocity:velocity:1.6.4"), MavenArtifactResolver.resolve("commons-lang:commons-lang:2.4")) .addWebResource(EmptyAsset.INSTANCE, "beans.xml"); + return ar; } @Inject private Instance velocityMailMessage; + @Inject + private ResourceProvider resourceProvider; + @Inject private MailConfig mailConfig; @@ -128,7 +133,7 @@ public void testVelocityTextMailMessage() throws MessagingException, IOException .replyTo(replyToAddress) .to(toAddress, toName) .subject(new TextTemplate(subject)) - .bodyText(new ClassPathTemplate("template.text.velocity")) + .bodyText(new InputStreamTemplate(resourceProvider.loadResourceStream("template.text.velocity"))) .put("version", version) .importance(MessagePriority.HIGH) .send(session.get()); @@ -184,10 +189,10 @@ public void testVelocityHTMLMailMessage() throws MessagingException, IOException .replyTo(replyToAddress, replyToName) .to(person) .subject(subject) - .bodyHtml(new ClassPathTemplate("template.html.velocity")) + .bodyHtml(new InputStreamTemplate(resourceProvider.loadResourceStream("template.html.velocity"))) .put("version", version) .importance(MessagePriority.HIGH) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(session.get()); } finally @@ -249,12 +254,12 @@ public void testVelocityHTMLTextAltMailMessage() throws MessagingException, IOEx .to(person.getEmail(), person.getName()) .subject(subject) .put("version", version) - .bodyHtmlTextAlt(new ClassPathTemplate("template.html.velocity"), new ClassPathTemplate("template.text.velocity")) + .bodyHtmlTextAlt(new InputStreamTemplate(resourceProvider.loadResourceStream("template.html.velocity")), new InputStreamTemplate(resourceProvider.loadResourceStream("template.text.velocity"))) .importance(MessagePriority.LOW) .deliveryReceipt(fromAddress) .readReceipt("seam.test") - .addAttachment(new ClassPathEmailAttachment("template.html.velocity", "text/html", ContentDisposition.ATTACHMENT)) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) + .addAttachment(new InputStreamAttachment(resourceProvider.loadResourceStream("template.html.velocity"),"template.html.velocity", "text/html", ContentDisposition.ATTACHMENT)) + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(); } finally @@ -325,12 +330,12 @@ public void testSMTPSessionAuthentication() throws MessagingException, Malformed .to(person.getEmail(), person.getName()) .subject(subject) .put("version", "Seam 3") - .bodyHtmlTextAlt(new ClassPathTemplate("template.html.velocity"), new ClassPathTemplate("template.text.velocity")) + .bodyHtmlTextAlt(new InputStreamTemplate(resourceProvider.loadResourceStream("template.html.velocity")), new InputStreamTemplate(resourceProvider.loadResourceStream("template.text.velocity"))) .importance(MessagePriority.LOW) .deliveryReceipt(fromAddress) .readReceipt("seam.test") - .addAttachment(new ClassPathEmailAttachment("template.html.velocity", "text/html", ContentDisposition.ATTACHMENT)) - .addAttachment(new URLEmailAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) + .addAttachment(new InputStreamAttachment(resourceProvider.loadResourceStream("template.html.velocity"), "template.html.velocity", "text/html", ContentDisposition.ATTACHMENT)) + .addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE)) .send(gmailSession); } finally @@ -369,7 +374,7 @@ public void testVelocityTextMailMessageSendFailed() .replyTo(replyToAddress) .to(toAddress, toName) .subject(new TextTemplate(subject)) - .bodyText(new ClassPathTemplate("template.text.velocity")) + .bodyText(new InputStreamTemplate(resourceProvider.loadResourceStream("template.text.velocity"))) .put("version", version) .importance(MessagePriority.HIGH) .send(session.get()); diff --git a/freemarker/impl/src/main/java/org/jboss/seam/mail/templating/freemarker/FreeMarkerMailMessageImpl.java b/freemarker/impl/src/main/java/org/jboss/seam/mail/templating/freemarker/FreeMarkerMailMessageImpl.java index 9fa02a1..b6eba9d 100644 --- a/freemarker/impl/src/main/java/org/jboss/seam/mail/templating/freemarker/FreeMarkerMailMessageImpl.java +++ b/freemarker/impl/src/main/java/org/jboss/seam/mail/templating/freemarker/FreeMarkerMailMessageImpl.java @@ -29,7 +29,7 @@ import javax.mail.Session; import javax.mail.internet.InternetAddress; -import org.jboss.seam.mail.attachments.BaseEmailAttachment; +import org.jboss.seam.mail.attachments.BaseAttachment; import org.jboss.seam.mail.core.EmailAttachment; import org.jboss.seam.mail.core.EmailContact; import org.jboss.seam.mail.core.EmailMessage; @@ -303,7 +303,7 @@ public FreeMarkerMailMessage iCal(String html, byte[] bytes) { emailMessage.setType(EmailMessageType.INVITE_ICAL); emailMessage.setHtmlBody(html); - emailMessage.addAttachment(new BaseEmailAttachment(null, "text/calendar;method=CANCEL", ContentDisposition.INLINE, bytes, "urn:content-classes:calendarmessage")); + emailMessage.addAttachment(new BaseAttachment(null, "text/calendar;method=CANCEL", ContentDisposition.INLINE, bytes, "urn:content-classes:calendarmessage")); return this; } diff --git a/velocity/impl/src/main/java/org/jboss/seam/mail/templating/velocity/VelocityMailMessageImpl.java b/velocity/impl/src/main/java/org/jboss/seam/mail/templating/velocity/VelocityMailMessageImpl.java index 2df3dd2..43e5923 100644 --- a/velocity/impl/src/main/java/org/jboss/seam/mail/templating/velocity/VelocityMailMessageImpl.java +++ b/velocity/impl/src/main/java/org/jboss/seam/mail/templating/velocity/VelocityMailMessageImpl.java @@ -31,7 +31,7 @@ import org.apache.velocity.exception.MethodInvocationException; import org.apache.velocity.exception.ParseErrorException; import org.apache.velocity.exception.ResourceNotFoundException; -import org.jboss.seam.mail.attachments.BaseEmailAttachment; +import org.jboss.seam.mail.attachments.BaseAttachment; import org.jboss.seam.mail.core.EmailAttachment; import org.jboss.seam.mail.core.EmailContact; import org.jboss.seam.mail.core.EmailMessage; @@ -300,7 +300,7 @@ public VelocityMailMessage iCal(String html, byte[] bytes) { emailMessage.setType(EmailMessageType.INVITE_ICAL); emailMessage.setHtmlBody(html); - emailMessage.addAttachment(new BaseEmailAttachment(null, "text/calendar;method=CANCEL", ContentDisposition.INLINE, bytes, "urn:content-classes:calendarmessage")); + emailMessage.addAttachment(new BaseAttachment(null, "text/calendar;method=CANCEL", ContentDisposition.INLINE, bytes, "urn:content-classes:calendarmessage")); return this; }