Write a program using MongoDB to compose a web news-letter consisting of videos, images, text use python MongoDB interface.


  1. Computer System with Windows/Linux/Open Source Operating System.
  2. JDK
  3. Eclipse / Netbeans (for J2EE)
  4. Web Server (Apache Tomcat /Glassfish)
  5. MongoDB Server and Client


This experiment will send web newsletter created using JSP to the desired recipients. The contents will also be stored in MongoDB database.

To send an email using a JSP is simple enough but to start with its necessary to have JavaMail API and Java Activation Framework (JAF) installed on machine. These files can be downloaded free from Oracle’s official website. Download and unzip these files, in the newly created top level directories. Programmer needs to add mail.jar and activation.jar files in java CLASSPATH.

Send a Simple Email: Here is an example to send a simple email from your machine. Here it is assumed that your localhost is connected to the internet and capable enough to send an email. Same time make sure all the jar files from Java Email API package and JAF package ara available in CLASSPATH.

<%@ page import="*,java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
   String result;
   // Recipient's email ID needs to be mentioned.
   String to = "";
   // Sender's email ID needs to be mentioned
   String from = "";
   // Assuming you are sending email from localhost
   String host = "localhost";
   // Get system properties object
  Properties properties = System.getProperties();
   // Setup mail server
   properties.setProperty("", host);
   // Get the default Session object.
   Session mailSession = Session.getDefaultInstance(properties);
      // Create a default MimeMessage object.
      MimeMessage message = new MimeMessage(mailSession);
      // Set From: header field of the header.
      message.setFrom(new InternetAddress(from));
      // Set To: header field of the header.
      message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
      // Set Subject: header field
      message.setSubject("This is the Subject Line!");
      // Now set the actual message
      message.setText("This is actual message");
      // Send message
      result = "Sent message successfully....";
   }catch (MessagingException mex) {
      result = "Error: unable to send message....";
<title>Send Email using JSP</title>
<h1>Send Email using JSP</h1>
<p align="center">
   out.println("Result: " + result + "\n");

Now let us put above code in SendEmail.jsp file and call this JSP using URL http://localhost:8080/SendEmail.jsp which would send an email to given email ID and would display following response:

To send an email to multiple recipients, following methods would be used to specify multiple email IDs:

void addRecipients(Message.RecipientType type,Address[] addresses) throws MessagingException

Here is the description of the parameters:

  • type: This would be set to TO, CC or BCC. Here CC represents Carbon Copy and BCC represents Black Carbon Copy. Example Message.RecipientType.TO
  • addresses: This is the array of email ID. You would need to use InternetAddress() method while specifying email IDs

Leave a Reply

Your email address will not be published. Required fields are marked *