Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Java Mail Interview Questions and Answers

Ques 6. Explain POP, SMTP and IMAP protocols.

POP: The Post Office Protocol is an application-level protocol within an intranet which are used by the local e-mail clients to send and retrieve e-mails from a remote server those are connected using TCP/IP. POP is one of the most prevalent protocol fro the usage of e-mail. The POP and its procedures support the end-users with dial-up network connections.

POP allows the users to retrieve e-mail when connected and later allows viewing and altering the retrieved messages. This is done with a promising feature – without staying connected. The process of using emails over POP is to connect, retrieve the messages, and store them on the user’s PC as a new message. Later these messages can be ‘deleted from the server’ and disconnecting the server – makes POP a distinguished protocol.

SMTP: Simple Mail Transfer Protocol, for sending email between ‘servers’. Most of the emailing systems implement the messages over internet use SMTP. The message sent from one server to another server, and then the message can be retrieved by an email client. The client uses either POP or IMAP. In addition to this process, SMTP is also generally used for message sending and retrieval from a mail client to a mail server. This is the reason why the need of POP or IMAP server and the SMTP servers at the time of configuring the email application.

IMAP: Short for Internet Message Access Protocol. This is another most prevalent protocol of internet standard for email usage apart from POP. Usually all the modern email server and client supports these two protocols for transmitting the email messages. For Example Gmail server uses to transmit the message to a client such as Mozilla Thunderbird and Microsoft Outlook.

IMAP is an application layer protocol over internet that is operating from port no. 143 that allows the accessibility of email on a remote server by a client. IMAP supports the online and offline (disconnected) modes of operations. Usually the email clients using IMAP utilizes the facility of leaving the message on the server. The message lasts until the user explicitly deletes them. IMAP also allows multiple clients to have the accessibility of the same mailbox.

Is it helpful? Add Comment View Comments
 

Ques 7. Explain the use of MIME within message makeup.

Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(args[0])};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Hello");
msg.setSentDate(new Date());
msg.setText("Mail Message");

This section creates the actual message object and fills in the to, from, subject, date and content. There are also options to set the reply to, content and content type, and other header information. Since this is a MIME - Multipurpose Internet Mail Extensions - message, it need not be plain text.

A DataHandler can be set using setDataHandler() in MimeMessage to handle nontext parts. This is a simple one-part text message, the setText() can be used.

Is it helpful? Add Comment View Comments
 

Ques 8. Explain the structure of Javamail API

The JavaMail API has classes such as Message, Store and Transport. The API can be used to subclass for providing new protocols and some additional functionality when needed. The concrete subclasses of this API are MimeMessage and MimeBodyPart which are implemented widely by the internet mail protocols. The supporting protocols for Javamail API are IMAP4, POP3 and SMTP.

The Java mail architectural components include the following:

Abstract Layer: This layer declares the classes, interfaces and abstract methods that are intended for supporting the mail functions which all mailing systems supports.

Intranet Implementation Layer: The implementation of MIME internet standards and part of the abstract layer comprises this layer.

Java Bean Activation Framework: The encapsulation of message data and handling the data interacting commands is used by the Javabean Activation Framework.

Is it helpful? Add Comment View Comments
 

Ques 9. What are the advantages of JavaMail?

Potential advantages include - Java mail is used to create personal mail filter, simple mailing lists and personal mail applications. Java mail also includes the capabilities to add the emailing process to an enterprise application or even to create a full-fledged e-mail client. Many companies in the industry have written new e-mail clients using Java Mail.

Is it helpful? Add Comment View Comments
 

Ques 10. Sample code to send email from you java application.

You can use the JavaMail API to send emails from your Java application. Though the JavaMail API allows you to do many things including the ability to retrieve and read the emails or sending emails etc, this sample java program demonstrates how to send email from your Java application. Remember to change the email host (String host) to your email server host, otherwise it won't work.

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SimpleSendEmail {
public static void main(String[] args) {
// Collect the necessary information to send a simple message
// Make sure to replace the values for host, to, and from with
// valid information.
// host - must be a valid smtp server that you currently have
// access to.
// to - whoever is going to get your email
// from - whoever you want to be. Just remember that many smtp
// servers will validate the domain of the from address
// before allowing the mail to be sent.
String host = "server.myhost.com";
String to = "YourFriend@someemail.com";
String from = "Me@myhost.com";
String subject = "My First Email";
String messageText = "I am sending a message using the"
+ " JavaMail API.n"
+ "Here type your message.";
boolean sessionDebug = false;
// Create some properties and get the default Session.
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(props, null);
// Set debug on the Session so we can see what is going on
// Passing false will not echo debug info, and passing true
// will.
session.setDebug(sessionDebug);
try {
// Instantiate a new MimeMessage and fill it with the
// required information.
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
// Hand the message to the default transport service
// for delivery.
Transport.send(msg);
}
catch (MessagingException mex) {
mex.printStackTrace();
}
}
}

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2024 WithoutBook