jQuery in Action, 2nd edition
The moose likes Other JSE/JEE APIs and the fly likes Java Mail Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Java Mail Server" Watch "Java Mail Server" New topic

Java Mail Server

Deepak Sharma

Joined: Mar 09, 2001
Posts: 4
hi EveryOne,
I want to make a mail server using javamail api.
I am able to send the mail but not able to recieve. I have gone through documents of javamail api, there I am getting imap hostname. What is this imap hostname? the overall need is how to recieve message, what are the things required for this & to which the classpath should be setted. please send me the code of this if possible.
i have in my system:
please specify if any thing required more.
thank you
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Java Mail questions should really be asked in the "Other Java APIs" forum. You are much more likely to get a sensible answer there, so I've moved this thread for you.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog

Joined: Apr 16, 2001
Posts: 1
Extract your jar files ie, activation.jar & mail.jar present in your jaf1.0.1 & javamail1.2 packages.
A javax folder will be created in your weblogic\classes folder. set your classpath to include the weblogic\classes folder
And for your info. Imap hostname means the name of your computer where your mailserver is present.Your mailserver should be supporting the imap protocol. Imap protocol is the protocol available for reading of messages
[This message has been edited by sanjuantony (edited April 16, 2001).]
Marcela Blei
Ranch Hand

Joined: Jun 28, 2000
Posts: 477
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Subramaniam Krishnan

Joined: Jun 04, 2001
Posts: 10
you can either use IMAP or POP to receive the mails. Eg.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;

public class POP3Client {
public static void main(String[] args) {

Properties props = new Properties();
// host name here is the POP or IMAP server.
String host = "";
//here u can use the username to access the Inbox
String username = "";
String password = "";
//provider can either be POP or IMAP
String provider = "pop3";
try {
// Connect to the POP3 server
Session session = Session.getDefaultInstance(props, null);
System.out.println("I am after Session creation");
Store store = session.getStore(provider);
System.out.println("I am after getting the Store");
store.connect(host, username, password);

// Open the folder
Folder inbox = store.getFolder("INBOX");
if (inbox == null) {
System.out.println("No INBOX");

// Get the messages from the server
Message[] messages = inbox.getMessages();
for (int i = 0; i < messages.length; i++) {
System.out.println("------------ Message " + (i+1)
+ " ------------");
// Close the connection
// but don't remove the messages from the server

catch (Exception e) {

public static void printMessage(Message m) throws Exception {
// Print the message header
Address[] from = m.getFrom();
if (from != null) {
for (int i = 0; i < from.length; i++) {
System.out.println("From: " + from[i]);

Address[] to = m.getRecipients(Message.RecipientType.TO);
if (to != null) {
for (int i = 0; i < to.length; i++) {
System.out.println("To: " + to[i]);

String subject = m.getSubject();
if (subject != null) {
System.out.println("Subject: " + subject);

Date d = m.getSentDate();
if (d != null) {
System.out.println("Date: " + d);
// Print a blank line to separate the header from the body
// Print the message body
Object content = m.getContent();
if (content instanceof String) {
else if (content instanceof InputStream) {
InputStream in = (InputStream) content;
int c;
while ((c = in.read()) != -1) System.out.write(c);
else {
System.out.println("Unrecognized Content Type");

Anup Agrawal

Joined: Jun 09, 2001
Posts: 19
Dear Subramaniam Krishnan,
Tell me how to send msg using java mail API. I tried it by demo program given with java mail api as explained at http://developer.java.sun.com/developer/onlineTraining/JavaMail/exercises/MailSetup/help.html But unable to do so. It is giving the error of pop authentication. I am unable to understand where to give the password. Please help me out.

santosh vashist

Joined: May 14, 2001
Posts: 25
hello anup!
have u extracted javamail1.2.1. in that docs.. try running msgsendexample.java to run this u should have a mailserver configured to any system in network..
the host name u will be giving here is the name of the server
to which the mailserver is configured.
if u r running javaMailservlet.java
then here
imaphostname : mailserver configured sytem name
name: login name of the outlook express or any thing configured in ur system
password.: password ur inbox in outlookexpress
It is sorta covered in the JavaRanch Style Guide.
subject: Java Mail Server