Skip to content

Commit

Permalink
add Seam Render to example
Browse files Browse the repository at this point in the history
add tests for Seam Render
  • Loading branch information
codylerum committed Mar 9, 2011
1 parent 96bb722 commit 0e2f688
Show file tree
Hide file tree
Showing 6 changed files with 517 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/sendmail/pom.xml
Expand Up @@ -87,6 +87,13 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jboss.seam.mail</groupId>
<artifactId>seam-mail-render-impl</artifactId>
<version>3.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jboss.seam.config</groupId>
Expand Down Expand Up @@ -149,6 +156,12 @@
<artifactId>subethasmtp</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<scope>test</scope>
</dependency>

<!-- Needed for running tests (you may also use TestNG) -->
<dependency>
Expand Down
Expand Up @@ -29,8 +29,10 @@
import org.jboss.seam.mail.core.enumurations.ContentDisposition;
import org.jboss.seam.mail.core.enumurations.MessagePriority;
import org.jboss.seam.mail.templating.freemarker.FreeMarkerTemplate;
import org.jboss.seam.mail.templating.render.RenderTemplate;
import org.jboss.seam.mail.templating.velocity.CDIVelocityContext;
import org.jboss.seam.mail.templating.velocity.VelocityTemplate;
import org.jboss.seam.render.TemplateCompiler;
import org.jboss.seam.solder.resourceLoader.ResourceProvider;
/**
*
Expand All @@ -51,6 +53,9 @@ public class SendMail
@Inject
private ResourceProvider resourceProvider;

@Inject
private Instance<TemplateCompiler> templateCompiler;

@Inject
private Instance<Session> session;

Expand Down Expand Up @@ -130,4 +135,35 @@ public void sendHTMLwithAlternativeVelocity() throws MalformedURLException
.addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE))
.send(session.get());
}

public void sendHTMLRender() throws MalformedURLException
{
mailMessage.get()
.from("seam@test.test", "Seam Framework")
.to(person)
.subject("HTML Message from Seam Mail - " + java.util.UUID.randomUUID().toString())
.bodyHtml(new RenderTemplate(templateCompiler.get(), "template.html.render"))
.put("version", "Seam 3")
.importance(MessagePriority.HIGH)
.addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE))
.send(session.get());
}

public void sendHTMLwithAlternativeRender() throws MalformedURLException
{
mailMessage.get()
.from("seam@test.test", "Seam Framework")
.to(person.getEmail(), person.getName())
.subject("HTML+Text Message from Seam Mail - " + java.util.UUID.randomUUID().toString())
.put("version", "Seam 3")
.bodyHtmlTextAlt(
new RenderTemplate(templateCompiler.get(), "template.html.render"),
new RenderTemplate(templateCompiler.get(), "template.text.render"))
.importance(MessagePriority.LOW)
.deliveryReceipt("seam@jboss.org")
.readReceipt("seam@jboss.org")
.addAttachment("template.html.render", "text/html", ContentDisposition.ATTACHMENT, resourceProvider.loadResourceStream("template.html.render"))
.addAttachment(new URLAttachment("http://www.seamframework.org/themes/sfwkorg/img/seam_icon_large.png", "seamLogo.png", ContentDisposition.INLINE))
.send(session.get());
}
}
8 changes: 8 additions & 0 deletions examples/sendmail/src/main/resources/template.html.render
@@ -0,0 +1,8 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<p><b>Dear <a href="mailto:@{person.email}">@{person.name}</a>,</b></p>
<p>This is an example <i>HTML</i> email sent by @{version} and Seam Render.</p>
<p><img src="@{mailContext.insert("seamLogo.png")}" /></p>
<p>It has an alternative text body for mail readers that don't support html.</p>
</body>
</html>
3 changes: 3 additions & 0 deletions examples/sendmail/src/main/resources/template.text.render
@@ -0,0 +1,3 @@
Hello @{person.name},

This is the alternative text body for mail readers that don't support html. This was sent with @{version} and Seam Render.
4 changes: 4 additions & 0 deletions examples/sendmail/src/main/webapp/home.xhtml
Expand Up @@ -40,6 +40,10 @@
<p>
<h:commandButton action="#{sendMail.sendHTMLVelocity}" value="Send HTML Email with Velocity" onclick="value='Sending...';"/>
<h:commandButton action="#{sendMail.sendHTMLwithAlternativeVelocity}" value="Send HTML+Text Email with Velocity" onclick="value='Sending...';"/>
</p>
<p>
<h:commandButton action="#{sendMail.sendHTMLRender}" value="Send HTML Email with Seam Render" onclick="value='Sending...';"/>
<h:commandButton action="#{sendMail.sendHTMLwithAlternativeRender}" value="Send HTML+Text Email with Seam Render" onclick="value='Sending...';"/>
</p>
<p>
<h:outputText value="Message Sent!" rendered="#{facesContext.postback and empty facesContext.messageList}" style="color: green;"/>
Expand Down

0 comments on commit 0e2f688

Please sign in to comment.