<?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>Benny's Blog &#187; open source</title>
	<atom:link href="http://blog.projectnibble.org/tag/open-source/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.projectnibble.org</link>
	<description>House Of Code</description>
	<lastBuildDate>Fri, 13 Aug 2010 15:06:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Vesijama, the Very Simple Java Mail library</title>
		<link>http://blog.projectnibble.org/2009/04/27/vesijama-very-simple-java-mail/</link>
		<comments>http://blog.projectnibble.org/2009/04/27/vesijama-very-simple-java-mail/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 20:26:23 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[mailing]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[rfc]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=67</guid>
		<description><![CDATA[In Java, sending emails can be a pain unless you're using a third party library. Now, the easiest one yet just went open source. Enter Vesijama, the Very Simple Java Mail library.]]></description>
			<content:encoded><![CDATA[<p><strong>Here&#8217;s the story about why I wrote a mail API wrapper in Java and made it Open Source. It is called <a href="http://code.google.com/p/vesijama/">Vesijama, Very Simple Java Mail</a>.</strong></p>
<p><span id="more-67"></span></p>
<h2>Prologue</h2>
<p>So I was looking into sending some emails from my little Java webapp, right. I thought: <q>easy, java has built in mail support called <a href="http://java.sun.com/products/javamail/">JavaMail</a></q>. Well, I was in for an unpleasant surprise when I found out I was merely handed the sand grains to build my castle. I can&#8217;t just say to Java&#8217;s mailing library <q>Hey, here&#8217;s what I want to send, and here are the addresses I need it sent to</q>, no. I can say however <q>I want you to formulate a mixed multipart message with the following attributes and these addresses encoded into special objects and oh yeah, define some mimemessage bodyparts for these attachments and use the following headers and put everything in a very specific nested structure dot dot dot</q>.</p>
<p>You actually need to research the RFC for mail structures to do it properly! In case you&#8217;re interested (which you&#8217;re not), check out this <a href="http://www.lesnikowski.com/mail/rfc.aspx">page of useful email rfc&#8217;s</a>. The rfc&#8217;s <a href="http://www.lesnikowski.com/mail/Rfc/rfc822.txt">822</a>, <a href="http://www.lesnikowski.com/mail/Rfc/rfc2047.txt">2047</a> and <a href="http://www.lesnikowski.com/mail/Rfc/rfc2045.txt">2045</a> are referenced in Java&#8217;s <a href="http://java.sun.com/products/javamail/javadocs/javax/mail/internet/MimePart.html">MimePart</a> alone. That&#8217;s just stupid, I can&#8217;t think of anything else where the JDK is forcing developers to work on such a low level where you need to deal with rfc&#8217;s.</p>
<p>An example of the JavaMail madness can be found on a <a href="http://www.velocityreviews.com/forums/showthread.php?p=3850368">thread at velocityreviews.com</a>, where someone asks for a simple tutorial to learn how to simply send emails using JavaMail. Here&#8217;s the answer of one of the members:</p>
<blockquote style="font-size:8pt"><p>First, you need to read and understand the relevant RFCs governing Internet<br />
email, if you don&#8217;t already understand this. I&#8217;d recommend starting with:</p>
<p>RFC 2821 &#8211; Simple Mail Transfer (SMTP)<br />
RFC 2822 &#8211; Format of Internet Messages<br />
RFC 1939 &#8211; Post Office Protocol (POP3)<br />
RFC 2060 &#8211; Internet Mail Access Protocol (IMAP)</p>
<p>then moving on to MIME:</p>
<p>RFCs 2045 &#8211; 2049 &#8211; Multipurpose Internet Mail Extensions (MIME)</p>
<p>Once you understand this, you should be able to figure out JavaMail using<br />
the tutorial at http://java.sun.com/developer/onlineTraining/JavaMail/contents.html,<br />
(which is, incidentally, the first hit returned from a Google search on the<br />
term &#8220;javamail tutorial&#8221;), along with the JavaDoc that is shipped along<br />
with the JavaMail libraries. If you have any specific questions about how<br />
JavaMail is to be used, please post them to the news group and you&#8217;ll be<br />
pretty sure to get an answer.</p>
<p>Cheers!</p></blockquote>
<p>With all his good intentions, this guy doesn&#8217;t realize he&#8217;s completely scaring the mail novice away; people looking for a way to send emails shouldn&#8217;t be required to be RFC educated email engineers. I just now realize that maybe JavaMail wasn&#8217;t meant to be used by Joe sixpack, but rather by third-party library vendors. Also, realize that JavaMail is much more than just smtp client API. Still, when I began writing Vesijama there weren&#8217;t a whole lot of third-party options, let alone one as simple to use as Vesijama.</p>
<p>Don&#8217;t get me wrong though: it&#8217;s not that the JavaMail API is so bad, it&#8217;s great actually. It allows for very finegrained configuration for pop3, smtp and everything mail related. It&#8217;s just that you don&#8217;t want regular Java developers to deal with API on such a low level: it takes a lot of time getting it right and the risk of a faulty implementation is very high, as the result will often work in <i>some</i> email (web) clients and subtle mistakes with significant consequences will go unnoticed.</p>
<h2>Enter Vesijama, the Very Simple Java Mail library</h2>
<p>To spare other developers the same fate, I decided to write a proper wrapper around the JavaMail smtp API so no Java developer needs to be bothered by this stuff and just keep pluggin&#8217; on an abstract business logic level. You know, just send the damn mails.</p>
<p>It took me quite a while to get it right since email clients, especially web clients, are very sensitive to incorrect nested structures. I&#8217;m happy to say I&#8217;ve succesfully used this when I was working for a commercial company, which means it has been professionally tested with a broad range of email (web) clients.</p>
<p>Enter Vesijama. It´s been a while since I wrote this little framework, I´ve only recently had the time to properly prepare the code for an Open Source release. At the time of writing the library I didn&#8217;t know about <a href="http://static.springframework.org/spring/docs/2.0.x/reference/mail.html">Spring&#8217;s mailing facility</a> or <a href="http://commons.apache.org/email/userguide.html">Apache&#8217;s Commons Mail</a> libraries, but in hindsight I think there&#8217;s a place for Vesijama since in my completely biased opinion it is by far the easiest to use framework. Look it up over at <a href="http://code.google.com/p/vesijama/"><strong>Vesjiama at Google Code</strong></a>.</p>
<p>Here&#8217;s the one and only code example from the Vesijama project page:</p>
<pre  name="code" class="java">
final Email email = new Email();

email.setFromAddress("lollypop", "lolly.pop@somemail.com");
email.setSubject("hey");
email.addRecipient("C. Cane", "candycane@candyshop.org", RecipientType.TO);
email.addRecipient("C. Bo", "chocobo@candyshop.org", RecipientType.BCC);
email.setText("We should meet up! ;)");
email.setTextHTML("<img src='cid:wink1'><b>We should meet up!</b><img src='cid:wink2'>");

// embed images and include downloadable attachments
email.addEmbeddedImage("wink1", imageByteArray, "image/png");
email.addEmbeddedImage("wink2", imageDatesource);
email.addAttachment("invitation", pdfByteArray, "application/pdf");
email.addAttachment("dresscode", odfDatasource);

new Mailer("smtp.host.com", 25, "username", "password").sendMail(email);
</pre>
<p>Oh wow, is that it? Well, I just imagine masses of people gazing with open mouths thinking that, but that&#8217;ll never happen because nobody realizes how much effort went in the rfc research. And the very few lines that make up the mail structure don&#8217;t look very impressive either&#8230; the thing is it has to be just right; mail clients aren&#8217;t very forgiving. It often amazes me how many thousands of lines of rfc text results in miniscule implementations, but luckily in this case at least if you do it right, it works in all email clients that properly handle emails according the rfc&#8217;s.</p>
<p>Anyway, the library suited me and now it&#8217;s yours too. Enjoy.</p>
<p><a href="http://blog.projectnibble.org/2009/04/27/vesijama-very-simple-java-mail/trackback/">trackback</></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2009/04/27/vesijama-very-simple-java-mail/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>
