forked from jboss-eap/quickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.html
96 lines (72 loc) · 7.44 KB
/
README.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<html><head><title>README</title><link href="https://raw.github.com/pmuir/github-flavored-markdown/gh-pages/shared/css/documentation.css" rel="stylesheet"></link><link href="https://raw.github.com/github/github-flavored-markdown/gh-pages/shared/css/pygments.css" rel="stylesheet"></link></head><body><h1 id="toc_0">mail: E-Mail Example using CDI (Contexts and Dependency Injection) and JSF (JavaServer Faces)</h1>
<p>Author: Joel Tosi
Level: Beginner
Technologies: JavaMail, JSF, CDI
Summary: Demonstrates the use of JavaMail
Target Product: EAP</p>
<h2 id="toc_1">What is it?</h2>
<p>This example demonstrates sending email with the use of <em>CDI 1.0</em> and <em>JSF 2.0</em> in <em>JBoss AS 7</em>.</p>
<p>The example uses the default Mail provider that comes out of the box with <em>JBoss Enterprise Application Platform 6</em> and <em>JBoss AS 7</em>. It uses your local mail relay and the default SMTP port of 25.</p>
<p>The configuration of the mail provider is found in the <code>JBOSS_HOME/standalone/configuration/standalone.xml</code> if you are running a standalone server or in the <code>JBOSS_HOME/domain/configuration/domain.xml</code> file if you are running in a managed domain. An example of the mail subsystem XML configuration is provided below:</p>
<div class="highlight"><pre><span class="nt"><subsystem</span> <span class="na">xmlns=</span><span class="s">"urn:jboss:domain:mail:1.0"</span><span class="nt">></span>
<span class="nt"><mail-session</span> <span class="na">jndi-name=</span><span class="s">"java:jboss/mail/Default"</span> <span class="nt">></span>
<span class="nt"><smtp-server</span> <span class="na">address=</span><span class="s">"localhost"</span> <span class="na">port=</span><span class="s">"25"</span><span class="nt">/></span>
<span class="nt"></mail-session></span>
<span class="nt"><mail-session</span> <span class="na">jndi-name=</span><span class="s">"java:/MyOtherMail"</span><span class="nt">></span>
<span class="nt"><smtp-server</span> <span class="na">address=</span><span class="s">"localhost"</span> <span class="na">port=</span><span class="s">"9999"</span><span class="nt">></span>
<span class="nt"><login</span> <span class="na">name=</span><span class="s">"nobody"</span> <span class="na">password=</span><span class="s">"pass"</span><span class="nt">/></span>
<span class="nt"></smtp-server></span>
<span class="nt"><pop3-server</span> <span class="na">address=</span><span class="s">"example.com"</span> <span class="na">port=</span><span class="s">"1234"</span><span class="nt">/></span>
<span class="nt"><imap-server</span> <span class="na">address=</span><span class="s">"example.com"</span> <span class="na">port=</span><span class="s">"432"</span><span class="nt">></span>
<span class="nt"><login</span> <span class="na">name=</span><span class="s">"nobody"</span> <span class="na">password=</span><span class="s">"pass"</span><span class="nt">/></span>
<span class="nt"></imap-server></span>
<span class="nt"></mail-session></span>
<span class="nt"></subsystem></span>
</pre>
</div>
<p>The example is a web application that takes <code>To</code>, <code>From</code>, <code>Subject</code>, and <code>Message Body</code> input and sends mail to that address. The front end is a JSF page with a simple POJO backing, leveraging CDI for resource injection.</p>
<h2 id="toc_2">System requirements</h2>
<p>All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better.</p>
<p>The application this project produces is designed to be run on JBoss Enterprise Application Platform 6 or JBoss AS 7. </p>
<h2 id="toc_3">Configure Maven</h2>
<p>If you have not yet done so, you must <a href="../README.html#mavenconfiguration">Configure Maven</a> before testing the quickstarts.</p>
<h2 id="toc_4">Start JBoss Enterprise Application Platform 6 or JBoss AS 7 with the Web Profile</h2>
<ol>
<li>Open a command line and navigate to the root of the JBoss server directory.</li>
<li><p>The following shows the command line to start the server with the web profile:</p>
<div class="highlight"><pre><span class="n">For</span> <span class="n">Linux</span><span class="p">:</span> <span class="n">JBOSS_HOME</span><span class="o">/</span><span class="n">bin</span><span class="o">/</span><span class="n">standalone</span><span class="p">.</span><span class="n">sh</span>
<span class="n">For</span> <span class="n">Windows</span><span class="p">:</span> <span class="n">JBOSS_HOME</span><span class="o">\</span><span class="n">bin</span><span class="o">\</span><span class="n">standalone</span><span class="p">.</span><span class="n">bat</span>
</pre>
</div></li>
</ol>
<h2 id="toc_5">Build and Deploy the Quickstart</h2>
<p><em>NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See <a href="../README.html#buildanddeploy">Build and Deploy the Quickstarts</a> for complete instructions and additional options.</em></p>
<ol>
<li>Make sure you have started the JBoss Server as described above.</li>
<li>Open a command line and navigate to the root directory of this quickstart.</li>
<li><p>Type this command to build and deploy the archive:</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">clean</span> <span class="n">package</span> <span class="n">jboss</span><span class="o">-</span><span class="n">as</span><span class="p">:</span><span class="n">deploy</span>
</pre>
</div></li>
<li><p>This will deploy <code>target/jboss-as-mail.war</code> to the running instance of the server.</p></li>
</ol>
<h2 id="toc_6">Access the application </h2>
<p>The application will be running at the following URL: <a href="http://localhost:8080/jboss-as-mail">http://localhost:8080/jboss-as-mail</a>. </p>
<h2 id="toc_7">Undeploy the Archive</h2>
<ol>
<li>Make sure you have started the JBoss Server as described above.</li>
<li>Open a command line and navigate to the root directory of this quickstart.</li>
<li><p>When you are finished testing, type this command to undeploy the archive:</p>
<div class="highlight"><pre><span class="n">mvn</span> <span class="n">jboss</span><span class="o">-</span><span class="n">as</span><span class="p">:</span><span class="n">undeploy</span>
</pre>
</div></li>
</ol>
<h2 id="toc_8">Run the Quickstart in JBoss Developer Studio or Eclipse</h2>
<p>You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see <a href="../README.html#useeclipse">Use JBoss Developer Studio or Eclipse to Run the Quickstarts</a> </p>
<h2 id="toc_9">Debug the Application</h2>
<p>If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.</p>
<div class="highlight"><pre> <span class="n">mvn</span> <span class="n">dependency</span><span class="p">:</span><span class="n">sources</span>
<span class="n">mvn</span> <span class="n">dependency</span><span class="p">:</span><span class="n">resolve</span> <span class="o">-</span><span class="n">Dclassifier</span><span class="p">=</span><span class="n">javadoc</span>
</pre>
</div>
</body></html>