Ques : Describe process of sending an email

Ans :

On the Internet, each domain has email Server, when you send an email then the following
steps may be follows:

  1. When you send email, your email client whether its outlook express or your JSP
    program connects to your SMTP Server. For example, smtp.ignou.ac.in
  2. When client program communicates with SMTP Server, it sends sender and
    recipients’ mail address along with message body.
  3. The SMTP Server of the sender machine checks recipient email address especially its
    domain. If the domain name is same as the senders’, the message is directly send to
    recipient domain’s POP3 or IMAP server. If the domain name is different than SMTP
    server will have to communicate with other domain server.
  4. After finding the recipient server, the SMTP server of the sender machine has to
    communicate with Domain Name Server (DNS). The DNS translates the recipient
    address into IP address.
  5. The SMTP server of client machine is connected to recipient’s SMTP server.
  6. Now that the recipients SMTP server forwards the message to the domain’s POP3 or
    IMAP server.

Here is a simple email program:


<%@ page import=”java.io., 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 here.
String to = “abc@gmail.com”;


// Sender’s email ID needs to be mentioned here.
String from = “xyz@yahoo.com”;


// it is assumed that you are sending email from localhost
String host = “localhost”;


// get system properties object
Properties properties = System.getProperties();


// set SMTP mail server
properties.setProperty(“mail.smtp.host”, host);


// get the default Session object.
Session mailSession = Session.getDefaultInstance(properties);

try{

// 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.setSubject(“This is the Subject Line!”);
// Send the actual message
message.setContent(“<h1>This is actual message</h1>”,”text/html”);

// Send message
Transport.send(message);
result = “Sent message successfully….”;

}catch (MessagingException mex) {
mex.printStackTrace();
result = “Error: unable to send message….”;

}
%>
<html> <title> <head>Send HTML Email using JSP</title></head>
<body> <center> <h3>Send Email using JSP</h3>
</cneter> <p align=”center>
<%
out.println(“Result: ” + result + “\n”);
%>
<p> <body> <html>

Leave a Reply