Skip to content

2020Media

 

Newsflash

Block your brand from becoming a .xxx Find out more.
 
You are here: Home arrow Tools arrow Dynamic Content inc Java arrow Using JavaMail
Using JavaMail PDF Print E-mail

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);
%>

 
< Prev   Next >
Advertisement

Domain Search

Preferred Extensions -
.com .co.uk
.net .org
.me .eu
[+]
  • Narrow screen resolution
  • Wide screen resolution
  • Auto width resolution
  • Increase font size
  • Decrease font size
  • Default font size