1. Seam Mail Introduction 2. Configuration 3. Core Usage 4. Templating 5. Advanced Features



Similar documents
Mass ing Techniques

Client Configuration Secure Socket Layer. Information Technology Services 2010

How to use JavaMail to send

Division of Information Technology Lehman College CUNY

Outlook Express. Make Changes in Red: Open up Outlook Express. From the Menu Bar. Tools to Accounts - Click on. User Information

Outlook Express. Make Changes in Red: Open up Outlook Express. From the Menu Bar. Tools to Accounts - Click on Mail Tab.

Set up Outlook for your new student e mail with IMAP/POP3 settings

How to move to your account with MAC Mail

Sending an Message from a Process

Exchange Outlook Profile/POP/IMAP/SMTP Setup Guide

Patriots Outlook Configuration

JAVAMAIL API - SMTP SERVERS

Configuring Outlook 2013 For IMAP Connections

Outlook Express. Make Changes in Red: Open up Outlook Express. From the Menu Bar. Tools to Accounts - Click on Mail Tab.

Start Thunderbird and follow its prompts to configure it for your Yale Central account.

Dove User Guide Copyright Virgil Trasca

Knights Outlook 2013 Configuration

1. Open Thunderbird. If the Import Wizard window opens, select Don t import anything and click Next and go to step 3.

s sent to the FaxFinder fax server must meet the following criteria to be processed for sending as a fax:

Update Instructions

Set Up Setup with Microsoft Outlook 2007 using POP3

Knights Outlook Configuration

NeoMail Guide. Neotel (Pty) Ltd

Result: Adds an X-header named "X-Company" with the value of "Your Company Name"

IRMACS Setup. Your IRMACS is available internally by the IMAP protocol. The server settings used are:

Open Thunderbird. To set up an account in Thunderbird, from the Tools menu select Account Settings; choose account; then click Next.

Before starting to use the new system you will need to know the password to your e-wire account.

Sun Microsystems, Inc JavaMail API Design Specification version 1.0b

Campaign Enterprise User s Guide

Setup Guide. network support pc repairs web design graphic design Internet services spam filtering hosting sales programming

SERVLETS - SENDING

MS Enterprise Library 5.0 (Logging Application Block)

How to Set Up Your. Account

Configuring Thunderbird for Flinders Mail at home.

Package sendmailr. February 20, 2015

Summer Internship 2013

1. Open the preferences screen by opening the Mail menu and selecting Preferences...

Install and Configure Oracle Outlook Connector

Domains Help Documentation This document was auto-created from web content and is subject to change at any time. Copyright (c) 2016 SmarterTools Inc.

1 Accessing accounts on the Axxess Mail Server

BillMax Ticketing Installation and Usage Guide

Configuring Mozilla Thunderbird to Access Your SAS Account

Using Your New Webmail

Webmail. Setting up your account

Microsoft Outlook 2010

How to Set Up LSUS IMAP in Outlook 2013

Traveling Setup Microsoft Office

ing a large amount of recipients

Configuring Thunderbird with UEA Exchange 2007:

Mail 8.2 for Apple OSX: Configure IMAP/POP/SMTP

Configuring on Mobile Devices

Networking Applications

Using Your New Webmail

Traveling Setup Outlook Express

Sending on Blue Hornet

Listeners. Formats. Free Form. Formatted

What browsers can I use to view my mail?

SpamPanel Reseller Level Manual 1 Last update: September 26, 2014 SpamPanel

SerialMailer Manual. For SerialMailer 7.2. Copyright Falko Axmann. All rights reserved.

Oracle Java CAPS Binding Component User's Guide

Gate User's Guide javaprssrvr 4.0

Migration Manual (For Outlook 2010)

Getting started with IMAP for Aggi What is IMAP?

Follow these steps to configure Outlook Express to access your Staffmail account:

Windows Live Mail Setup Guide

Exchange (UCMAIL) Configuration Procedures

Neoteris IVE Integration Guide

MailEnable Web Mail End User Manual V 2.x

Configuring Outlook to send mail via your Exchange mailbox using an alternative address

How to Pop to Outlook

Create your first Newsletter

Filter NEW IN FIRSTCLASS CLIENT WHAT S NEW IN FIRSTCLASS 9.0. New Look. Login screen. List View Sort Order. Filtering Containers.

setup information for most domains hosted with InfoRailway.

Exchange Outlook Profile/POP/IMAP/SMTP Setup Guide

New Mexico State University

IOS 8: Configure IMAP/POP/SMTP

1. Open the Account Settings window by clicking on Account Settings from the Entourage menu.

Setting up your POP3 Mail Client (such as Outlook)

Step-by-Step Configuration Instructions

versasrs HelpDesk quality of service

THUNDERBIRD SETUP (STEP-BY-STEP)

Webmail Using the Hush Encryption Engine

How To Send Mail From A Macbook Access To A Pc Or Ipad With A Password Protected Address (Monroe Access) On A Pc (For Macbook) Or Ipa (For Ipa) On Pc Or Macbook (For

DLP Quick Start

How to set mail account on Outlook Express to read and send mail (for CSA/CSD users)

How to setup your iphone client

CSC E Mail. Mobile Device Configuration Settings and Setup Instructions

Instructions for Microsoft Outlook 2003

Configuration Manual for Lime Domains

8.7. NET SatisFAXtion Gateway Installation Guide. For NET SatisFAXtion 8.7. Contents

RoboMail Mass Mail Software

1 Introduction: Network Applications

Neoteris IVE Integration Guide

What s new in ProactiveWatch 2.1!

isecur User Guide for iphone

HGC SUPERHUB HOSTED EXCHANGE

Income Manager Enterprise E-Receipting

Outlook Connector Installation & Configuration groupwaresolution.net Hosted MS Exchange Alternative On Linux

Astaro Mail Archiving Getting Started Guide

Transcription:

Seam Mail

1. Seam Mail Introduction... 1 1.1. Getting Started... 1 2. Configuration... 3 2.1. Minimal Configuration... 3 3. Core Usage... 5 3.1. Intro... 5 3.2. Contacts... 5 3.2.1. String Based... 5 3.2.2. InternetAddress... 5 3.2.3. EmailContact... 6 3.2.4. Content... 7 3.2.5. Attachments... 7 4. Templating... 9 4.1. Basics... 9 4.2. Velocity... 9 4.3. FreeMarker... 9 5. Advanced Features... 11 5.1. MailTransporter... 11 5.2. MailConfig... 12 5.3. EmailMessage... 12 iii

iv

Chapter 1. Seam Mail Introduction Seam mail is an portable CDI extension designed to make working with Java Mail easier via standard methods or plugable templating engines. 1.1. Getting Started No better way to start off then with a simple example to show what we are talking about. @Inject private Instance<MailMessage> mailmessage; public void sendmail() { m.from("john Doe<john@test.com>").to("Jane Doe<jane@test.com>").subject(subject).bodyHtml(htmlBody).importance(MessagePriority.HIGH).send(); Very little is required to enable this level of functionality in your application. Let's start off with a little requenabletlsjndisessionnamejava.net.inetaddress.getlocalhost()ired configuration. 1

2

Chapter 2. Configuration By default the configuration parameters for Seam Mail are handled via configuration read from your application's seam-beans.xml. This file is then parsed by Seam Solder to configure the MailConfig class. You can override this and provide your own configuration outside of Seam Mail but we will get into that later. 2.1. Minimal Configuration First lets add the relevant maven configuration to your pom.xml <dependency> <groupid>org.jboss.seam.mail</groupid> <artifactid>seam-mail-impl</artifactid> <version>${seam.mail.version</version> </dependency> Now now that is out of the way lets provide JavaMail with the details of your SMTP server so that it can connect and send your mail on it's way. This configuration is handled via Seam Solder which reads in the configuration from your application's seam-beans.xml and configures the MailConfig class prior to injection. <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:s="urn:java:ee" xmlns:mail="urn:java:org.jboss.seam.mail.core" xsi:schemalocation=" http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd"> <mail:mailconfig serverhost="my-server.test.com" serverport="25"> <s:modifies/> </mail:mailconfig> </beans> 3

Chapter 2. Configuration That is all the configuration necessary to send a simple email message. Next we will take a look at how to configure and use the supported templating engines. Important JBoss AS 7.0.x does not correctly load all the modules to support sending mail AS7-1375 [https://issues.jboss.org/browse/as7-1375]. This is easily fixed By replacing the module definition at $JBOSS_HOME/modules/javax/activation/api/ main/module.xml with the following <module xmlns="urn:jboss:module:1.0" name="javax.activation.api"> <dependencies> <module name="javax.api" /> <module name="javax.mail.api" > <imports><include path="meta-inf"/></imports> </module> </dependencies> <resources> <resource-root path="activation-1.1.1.jar"/> <!-- Insert resources here --> </resources> </module> This will be fixed in AS 7.1.x 4

Chapter 3. Core Usage 3.1. Intro While Seam Mail does provide methods to produce templated email, there is a core set of functionality that is shared whether you use a templating engine or not. 3.2. Contacts At it's base an email consists of various destinations and content. Seam Mail provides a wide varerity of methods of ways to configure the following address fields From To CC BCC REPLY-TO 3.2.1. String Based Seam Mail leverages the JavaMail InternetAddress object internally for parsing and storage and provides a varargs method for each of the contact types. Thus you can provide either a String, multiple Strings or a String []. Addresses are parsed as RFC 822 addresses and can be a valid Email Address or a Name + Email Address. m.from("john Doe<john@test.com>").to("jane@test.com").cc("Dan<dan@test.com", "bill@test.com") 3.2.2. InternetAddress Since we leverage standard InternetAddress object we might as well provide a method to use it. m.from(new InternetAddress("John Doe<john@test.com>")) 5

Chapter 3. Core Usage 3.2.3. EmailContact Since applications frequently have their own object to represent a user who will have an email set to them we provide a simple interface which your object can implement. public interface EmailContact { public String getname(); public String getaddress(); Let's define this interface on an example user entity @Entity public class User implements EmailContact { private String username; //"john@test.com" private String firstname; //"John" private String lastname; //"Doe" public String getname() { return firstname + " " + lastname; public String getaddress() { return username; Now we can use our User object directly in an of the contact methods User user; m.from("john Doe<john@test.com>"); m.to(user); 6

Content 3.2.4. Content Adding content to a message is simply a matter of calling the appropriate method For plain text body m.bodytext("this is the body of my message"); For HTML body m.bodyhtml("this is the <b>body</b> of my message"); For HTML + plain text alternative body m.bodyhtmltextalt("this is the <b>body</b> of my message", "This is a plain text alternative"); 3.2.5. Attachments Attachments can be added using a few different implementations of the EmailAttachment.java interface BaseAttachment.java: byte[] InputStreamAttachment.java: java.io.inputstream FileAttachment.java: java.io.file URLAttachment.java: Loads attachment from URL 7

Chapter 3. Core Usage Attachments are added by providing the relevant information per implementations as well as a ContentDisposition which specifics if the attachment is simply "ATTACHMENT" or "INLINE" which allows the attachment to be referenced in the body when using templating m.addattachment(new FileAttachment(ContentDispostion.ATTACHMENT, new File("myFile")); Here is how to reference an attachment inline. Inline attachments are referenced by their filename. <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 Velocity.</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> 8

Chapter 4. Templating 4.1. Basics Instead of creating your message body as a String and setting it via the bodytext, bodyhtml and bodyhtmltextalt methods you can use integrated templating to substitute variables for values. Seam Mail supports templating in any of the body parts as well as the subject. The template can either be loaded as from a java.lang.string, java.io.file or java.io.inputstream Values to be used in place of your template variables are loaded via the put method, as a Map or optionally resolved via EL in Velocity 4.2. Velocity Example Usage. See Velocity documentation for syntax. m.subject(new VelocityTempalte("Weather for $city, $state") m.bodytext(new VelocityTemplate(new File("myFile.template")); m.put("city", "Boston"); m.put("state", "Massachusetts"); m.put("now", new Date()); A Velocity Template can be optionally created with an CDI injected CDIVelocityContext. This adds the ability to resolve your variables via the built in velocity context and a fall through to resolve CDI beans which are @Named. @Inject private CDIVelocityContext cdicontext; m.bodytext(new VelocityTemplate(new File("myFile.template"), cdicontext); 4.3. FreeMarker FreeMarker usage is essentially the same as Velocity except there is no EL functionality. Consult FreeMarker documentation for Syntax 9

Chapter 4. Templating m.subject(new FreeMarkerTemplate("ATTN: ${name") m.bodytext(new FreeMarkerTemplate("Hello ${name you have won 1M USD!")); m.put("name", "Ed Mcmahon"); 10

Chapter 5. Advanced Features 5.1. MailTransporter MailTransporter is an interface that allows you to control how the message is handled when the send() method is called. The default implementation simply sends the message with a javax.mail.session. The main drawback of this is that the thread is blocked until your configured email server accepts your messages. This can take milliseconds or minutes depending on the size of your message load on your SMTP server. While this may be fine for most simple cases, larger applications may wish to employ a queuing function so that messages appear to send instantly and do not block application execution. Overiding the default MailTransporter is simple MailTransporter mytransporter = new MailQueueTransporter(); MailMessage msg = mailmessage.get(); msg.setmailtransporter(mytransporter); A simple implementation might convert the message into a MimeMessage for sending and then fire as a CDI event so that a CDI @Observer can queue and send the message at a later time. The MailTransporter might look something like this. public class MailQueueTransporter implements Serializable, MailTransporter { private static final long serialversionuid = 1L; @Inject @QueuedEmail private Event<MimeMessage> queueevent; @Inject @ExtensionManaged private Instance<Session> session; @Override public EmailMessage send(emailmessage emailmessage) { MimeMessage msg = MailUtility.createMimeMessage(emailMessage, session.get()); 11

Chapter 5. Advanced Features queueevent.fire(msg); emailmessage.setmessageid(null); try { emailmessage.setlastmessageid(msg.getmessageid()); catch (MessagingException e) { throw new SendFailedException("Send Failed ", e); return emailmessage; 5.2. MailConfig MailConfig supports the following options serverhost - SMTP server to connect to serverport - Port to connect to SMTP server domainname - Used to build the Message-ID header. Format is UUID@domainName (uses java.net.inetaddress.getlocalhost().gethostname() if unset) username - Used when your SMTP server requires authentication password - Used when your SMTP server requires authentication enabletls - Allow TLS to be used on this connection requiretls - Require TLS to be used on this connection enablessl - Allow SSL to be used on this connection auth - Used when your SMTP server requires authentication jndisessionname - Load the javax.mail.session via JNDI rather than creating a new one 5.3. EmailMessage The MimeMessage as defined by javax.mail is a flexible and thus complicated object to work with in it's simplest configuration. Once multiple content types and attachments are added it can be downright confusing. To make working messages easier to work with, Seam Mail provides the 12

EmailMessage EmailMessage.java class as part of it's core implementation. An instance of EmailMessage is returned from all of the send methods as well after manually calling template merge methods. While Seam Mail does not provide a mechanism to receive messages it does provide a way to convert a javax.mail.mimemessage or javax.mail.message received via POP or IMAP back into a EmailMessage.java for easy of reading and manipulation via the MessageConverter. Session session = Session.getInstance(pop3Props, null); Store store = new POP3SSLStore(session, url); store.connect(); Folder inbox = store.getfolder("inbox"); inbox.open(folder.read_only); Message[] messages = inbox.getmessages(); List<EmailMessage> emailmessages = new LinkedList<EmailMessage>(); for (Message m : messages) { EmailMessage e = MessageConverter.convert(m); emailmessages.add(e); inbox.close(false); store.close(); 13

14