|
Manual
IntroductionVesijama is a lightweight wrapper framework for Sun's JavaMail (javax.mail API) for sending emails over smtp. Vesijama stands for Very Simple Java Mail and is designed to be as easy to use as possible, while still being able to do everything you want when sending email. Required librariesAlso see: NOTICE.txt Because Vesijama builds on the JavaMail library, it has the same dependencies and adds log4j to it (although the sourcecode could be modified to use Java's built in logging framework). Vesijama uses a couple of jars that are all opensource. These are the Apache log4j library and Sun JavaMail API library (only the smtp sublibraries). It uses the javax.activation package as well, which is shipped with JavaEE or is available as seperate package.
Example usageThere are only three classes exposed to the public. These are Email, Mailer and MailException. Simply create and fill an email and then call mailer.send(yourEmail) and that's it. Optionally catch runtime MailExceptions. Here's an example: 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);You can also pass in your own preconfigured mail Session instance, so this framework is backwards compatible with whatever you use now. AlternativesThere are some alternatives around, such as the Spring mailing framework or the Apache Commons Mail. However, Spring works a bit awkward with anonymous subclasses and stuff (and you need Spring in your dependencies), while Apache Commons Mail isn't as simple as it could be. Developing VesijamaThe sourcecode is relatively easy to understand and well commented. When you've checked out the code from the Subversion repository, you can run a build using ant compile, or ant jar if you like to create a jar while you're at it. To run the included test class use ant or ant run, which does the same. Make sure you provide some jvm arguments to indicate which smtp server to use for sending emails. Example: ant -Dhost=smtp.someserver.com -Dusername=joe -Dpassword=sixpack Also check out the developers version of the Javadoc: Some factoids
|
Sign in to add a comment