<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nepherte (dot) be &#187; Java</title>
	<atom:link href="http://www.nepherte.be/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nepherte.be</link>
	<description>About Nepherte, Mosiah and the person behind</description>
	<lastBuildDate>Mon, 30 Aug 2010 18:45:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Regular expression for Belgian phone numbers</title>
		<link>http://www.nepherte.be/regular-expression-for-belgian-phone-numbers/</link>
		<comments>http://www.nepherte.be/regular-expression-for-belgian-phone-numbers/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 22:02:15 +0000</pubDate>
		<dc:creator>Nepherte</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Belgian Phone Number]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Regular Expression]]></category>

		<guid isPermaLink="false">http://www.nepherte.be/?p=608</guid>
		<description><![CDATA[I needed a regular expression to parse Belgian phone numbers for a program I am writing. At first sight regular expressions can be quite difficult for people to understand. Luckily I have a course at University that studies the mathematics behind regular expressions and the languages they define. A lovely exercise. Belgian phone numbers comply [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a regular expression to parse Belgian phone numbers for a program I am writing. At first sight regular expressions can be quite difficult for people to understand. Luckily I have a course at University that studies the mathematics behind regular expressions and the languages they define. A lovely exercise.</p>
<p>Belgian phone numbers comply with following specifications:</p>
<ul>
<li> The 2 possible formats are 01 234 56 78 and 012 34 56 78.</li>
<li>The first 2 or 3 digits, the zone number, always start with a zero.</li>
<li>The entire phone numer counts 9 digits.</li>
</ul>
<p>There exist multiple other notations such as 012/34.56.78 and 012/34.56.78. The strenght of a regular expression is that it can describe all these notations in one line. This easy regular expression will do the necessary, though will also accept 10 digit numbers:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>,<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span>,<span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>You could however use a logical &#8216;or&#8217; between two expressions to make sure only 9 digit phone numbers are accepted:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Belgian cell phone numbers on the other hand have a slightly different format so another expression is necessary:</p>
<ul>
<li>The used format is 0412 34 56 67</li>
<li>The first 2 digits should always start with 04</li>
<li>The total number of digits should always be 10</li>
</ul>
<p>Again multiple notations exist to write down cell phone numbers. An expression that only accepts this format with the most commonly used notations is:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span>,<span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>. <span style="color: #7a0874; font-weight: bold;">&#93;</span>?<span style="color: #7a0874; font-weight: bold;">&#40;</span>?:\\d<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>A small program in java that uses these regular expressions could look like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.Matcher</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.Pattern</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PhoneNumberValidator <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// Check for valid Belgian phone numbers</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> isValidPhoneNumber<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> input<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
Pattern p <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[0](?:<span style="color: #000099; font-weight: bold;">\\</span>d{1,2})[/. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2,3})[. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2})[. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2})&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Matcher m <span style="color: #339933;">=</span> p.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span> m.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// Check for valid Belgian cell phone numbers</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">boolean</span> isValidCellPhoneNumber<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> input<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
Pattern p <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[0][4](?:<span style="color: #000099; font-weight: bold;">\\</span>d{2})[/. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2,3})[. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2})[. ]?(?:<span style="color: #000099; font-weight: bold;">\\</span>d{2})&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Matcher m <span style="color: #339933;">=</span> p.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span> m.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nepherte.be/regular-expression-for-belgian-phone-numbers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Howto: Send Mail Over SMTPS In Java</title>
		<link>http://www.nepherte.be/send-mail-over-smtps-in-java/</link>
		<comments>http://www.nepherte.be/send-mail-over-smtps-in-java/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 16:00:28 +0000</pubDate>
		<dc:creator>Nepherte</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[smtps]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.nepherte.be/?p=72</guid>
		<description><![CDATA[Introduction This tutorial will show you how to send mail in Java over SMTPS. SMTP, or Simple Mail Transfer Protocol, is the de facto standard for email transmissions across the internet. The SSL protocol, or Secure Socket Layer, provides an encrypted, secure connection. Many providers try to use this secure version of smtp and I [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong><br />
This tutorial will show you how to send mail in Java over SMTPS. SMTP, or Simple Mail Transfer Protocol, is the de facto standard for email transmissions across the internet. The SSL protocol, or Secure Socket Layer, provides an encrypted, secure connection. Many providers try to use this secure version of smtp and I encourage everyone to make use of it. </p>
<p><strong>Example code</strong><br />
In the example given, we will use the smtps server of Google. To use this server, you will need a Gmail account. The example makes use of the fictive email account &#8216;mail@gmail.com&#8217; with &#8216;password&#8217; and the <a href="http://java.sun.com/products/javamail/">JavaMail</a> library.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Properties</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Message</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Multipart</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Session</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.internet.InternetAddress</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.internet.MimeBodyPart</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.internet.MimeMessage</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.internet.MimeMultipart</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.mail.smtp.SMTPSSLTransport</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> sendMail<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> to, <span style="color: #003399;">String</span> from, <span style="color: #003399;">String</span> subject, Multipart content<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// create properties</span>
<span style="color: #003399;">Properties</span> props <span style="color: #339933;">=</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">getProperties</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// &lt; -- authorization, i.e. account &amp;amp; password is required --&gt;</span>
props.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.smtps.auth&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// &lt; -- it is important you use the correct port. smtp uses 25, smtps 465 --&gt;</span>
props.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.smtps.port&quot;</span>, <span style="color: #0000ff;">&quot;465&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// &lt; -- put the smtps server host address here --&gt;</span>
props.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.smtps.host&quot;</span>, <span style="color: #0000ff;">&quot;smtp.gmail.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create session</span>
Session session <span style="color: #339933;">=</span> Session.<span style="color: #006633;">getDefaultInstance</span><span style="color: #009900;">&#40;</span>props<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
session.<span style="color: #006633;">setDebug</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create content</span>
MimeMultipart msgContent <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MimeMultipart<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;alternative&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Text Mail</span>
MimeBodyPart html <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MimeBodyPart<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// &lt; -- we will send plain text, &quot;text/html&quot; is possible as well --&gt;</span>
html.<span style="color: #006633;">setContent</span><span style="color: #009900;">&#40;</span>content, <span style="color: #0000ff;">&quot;text/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
html.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MIME-Version&quot;</span>, <span style="color: #0000ff;">&quot;1.0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
html.<span style="color: #006633;">setHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span>, <span style="color: #0000ff;">&quot;text/plain; charset=iso-8859-1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
msgContent.<span style="color: #006633;">addBodyPart</span><span style="color: #009900;">&#40;</span>html<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
MimeMessage msg <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MimeMessage<span style="color: #009900;">&#40;</span>session<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
msg.<span style="color: #006633;">setContent</span><span style="color: #009900;">&#40;</span>content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// set sender and recipient</span>
msg.<span style="color: #006633;">setFrom</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> InternetAddress<span style="color: #009900;">&#40;</span>from<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
msg.<span style="color: #006633;">addRecipient</span><span style="color: #009900;">&#40;</span>Message.<span style="color: #006633;">RecipientType</span>.<span style="color: #006633;">TO</span>, <span style="color: #000000; font-weight: bold;">new</span> InternetAddress<span style="color: #009900;">&#40;</span>to<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
msg.<span style="color: #006633;">setSubject</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// transport the message</span>
<span style="color: #666666; font-style: italic;">// &lt; -- we will send the message over smtps --&gt;</span>
SMTPSSLTransport transport <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SMTPSSLTransport<span style="color: #009900;">&#41;</span>session.<span style="color: #006633;">getTransport</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;smtps&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// connect to server</span>
<span style="color: #666666; font-style: italic;">// &lt; -- fill in gmail email address and password --&gt;</span>
transport.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;smtp.gmail.com&quot;</span>, <span style="color: #0000ff;">&quot;mail@gmail.com&quot;</span>, <span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// send the message</span>
transport.<span style="color: #006633;">sendMessage</span><span style="color: #009900;">&#40;</span>msg, msg.<span style="color: #006633;">getAllRecipients</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// close the connection</span>
transport.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> catch<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
e.<span style="color: #006633;">getStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nepherte.be/send-mail-over-smtps-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
