UK Sales: 0800 035 6364 | | We'll Call You

Using Java Mail


Your Java account can be used to send emails using the JavaMail API. The provides fairly simple standard methods to send and receive emails, handle attachments and other mail related activities. You can find the API and documention on the Sun site at


Note: Spamming in any form is not acceptable, and is in violation of the terms and conditions of your Java Account.




Here are examples of pages sending test mesages. For the JSP page for sending mail click here and for the servlet version click here.


The source code for this type of function can be found on many places on the web, we recommend E-Mailing Through Java


You will need to include the following jar files in your WEB-INF/lib directory to use JavaMail.




(both of these are available from the Sun site.)


Example JSP

The example below shows you how to firstly connect to the local SMTP server and then create the JavaMail message and finally send the message through this SMTP connection. Change the parameters to suit your needs.

<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>

<% Properties props = new Properties();

props.put("", "localhost");
Session s = Session.getInstance(props,null);

InternetAddress from = new InternetAddress("ENTER_SENDER_EMAIL_ADDRESS");
InternetAddress to = new InternetAddress("ENTER_RECIPIENT_EMAIL_ADDRESS");

MimeMessage message = new MimeMessage(s);
message.addRecipient(Message.RecipientType.TO, to);


2020Media is a leading provider of small business Wi-Fi hotspots. If you want to offer free Wi-Fi to your customers or users, our service could be exactly what you are looking for. Our Hotspots are managed in the cloud, ultra-reliable and give you loads of information about behaviour patterns of your users. Read More   Read more...
2020Media introduces Moodle Hosting - UK servers and UK Moodle experts setup your site ready to use. Read more...
Special Offer for Longer Registration Periods Register or renew a .com, .net or .org domain name for 5 years we'll include 1 year free*. Read more...
2020Media is now offering zero-click installation of the popular TYPO3 content management system. Read more...

Our blog is regularly updated with news, tips and industry opinion.


  • AggieWestons
  • baker-and-mckenzie
  • arts-council-england
  • Big Finish
  • barratt-developments-logo
  • City-of-Lincoln-council-logo
  • brora-logo
  • DenisMacShane
  • Construction-Industry-Council
  • colchester