UK Sales: 0800 035 6364 | sales@2020media.com | 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 http://www.java.sun.com.

 

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

 

Examples

 

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.

 

mail.jar
activation.jar

 

(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("mail.smtp.host", "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.setFrom(from);
message.addRecipient(Message.RecipientType.TO, to);

message.setSubject("ENTER_SUBJECT");
message.setText("ENTER_MESSAGE");
Transport.send(message);
%>

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.

Clients

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