Tutorial #99: Send e-mail using JavaMail in JSP

Hi everyone!

JavaMail is a well known Java API used to send and receive email via SMTP, POP3 and IMAP. It mainly provides a platform-independent and protocol-independent framework to build mail and messaging applications. In addition, the JavaMail API package is also included in the Java EE platform.

JavaMail facilitates the sending of an e-mail via Gmail SMTP server, using both TLS and SSL connection. Through this tutorial, we will learn how to send an e-mail using JavaMail in a sample JSP page.

Pre-requisites: Eclipse IDE for Java EE developers, Apache Tomcat 7

Step 1: Create new Dynamic web project

Launch Eclipse IDE and create a new Dynamic web project called SendEmailUsingJSP with target runtime as Apache Tomcat 7.

Step 2: Add external jar files

In order to implement the sending of an e-mail, developers need to download and use the latest version of the JavaMail API in their web projects. For this tutorial, I will be using the mail-1.4.7.jar version of the JavaMail API. Make sure you add the .jar file in the WEB-INF/lib folder of your web project.

Step 3: Create JSP page

Create a new index.jsp page inside the WebContent folder of your web project and write the following code.


<%@ pageimport="javax.servlet.http.*,javax.servlet.*" %>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="java.io.*,java.util.*,javax.mail.*"%>

    //username for abc@gmail.com will be "abc"
	String username = "sender_username";
	String password = "sender_password";
	String result = null;

	try {
        Properties props = System.getProperties();
		props.setProperty("mail.transport.protocol", "smtp");
		props.setProperty("mail.host", "smtp.gmail.com");
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.port", "465");
		props.put("mail.debug", "true");
		props.put("mail.smtp.socketFactory.port", "465");
		props.put("mail.smtp.socketFactory.fallback", "false");

		Session emailSession = Session.getInstance(props,
				new javax.mail.Authenticator() {
					protected PasswordAuthentication getPasswordAuthentication() {
					return new PasswordAuthentication("sender_username","sender_password");

		Message message = new MimeMessage(emailSession);
		message.setFrom(new InternetAddress(
		message.setSubject("Test mail from Java");
		message.setText("Hello. this is a test");

		Transport transport = emailSession.getTransport("smtps");
		transport.connect("smtp.gmail.com", username, password);
		transport.sendMessage(message, message.getAllRecipients());

		result = "Successfully sent email";

	   } catch (MessagingException e) {
		result = "Unable to send email";
<title>Send Email using JSP</title>
		<h1>Send Email using JSP</h1>
	<p align="center">
			out.println("Result: " + result + "\n");

Finally, save all changes and run the application on the Tomcat server. If no errors occur then you should see the following output!


Reference: JavaMail API

Send e-mail using Jython in Oracle Data Integrator

Hello friends!

Oracle Data Integrator includes a built-in tool called OdiSendMail which is used to send an email through a SMTP server. However, OdiSendMail will work only if the mail server does not require authentication.

In this post, I will demonstrate how to send an e-mail with the help of Gmail’s SMTP server. Instead of going for the OdiSendMail tool, I will be using the Jython technology in order to implement the same functionality.

Pre-requisites: Oracle Data Integrator 11g (build version

Open ODI Studio and follow the below steps!

Step 1: Create a new Procedure

Create a new Procedure under any of your existing Projects in the Designer tab. Name the procedure SendEmail. Switch to Details and add a new entry.

create new procedure


Now, under Command on Target, you need to write the Jython code. Please make sure you have selected Technology as Jython.


Jython code

import smtplib
import string
BODY = string.join((
"From: %s" % 'senderemailaddress@gmail.com',
"To: %s" % 'recipientemailaddress@gmail.com',
"Subject: %s" % 'Test Mail',
"",'This is a test email from ODI'
), "\r\n")
sender = smtplib.SMTP('smtp.gmail.com',587)
sender.login('senderusername', 'senderpassword')

Note: You need to enter your valid Gmail credentials and replace sender and recipient address with valid email addresses in the above code.

Finally, run this procedure. Check the status of the operation under the Operator tab.




Source: Send mail in ODI using Gmail Credentials