File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Java Mail API & JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Java Mail API & JSP" Watch "Java Mail API & JSP" New topic

Java Mail API & JSP

elavazhagan selvaraj

Joined: Jan 23, 2001
Posts: 5
Can anybody tell, what are all the basic things to be needed to
develop automated mail using Java Mail API & JSP. As i already
have jsp environment & Mail API jars i need steps in developing


Elavazhagan Selvaraj<BR>
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
For testing, you will need a SMTP server for sending email, a POP3 server for recieving email. IMAP server for internet email.
ray bond
Ranch Hand

Joined: Oct 11, 2000
Posts: 111
where can I get pop3 server , IMAP server and IMAP server for testing purpose ??
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
That depends on your ISP at home, or your hosting company at work.
Tony Alicea

Joined: Jan 30, 2000
Posts: 3226
There is an introduction to JSP AND JAVAMAIL in:

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Ajan Balakrishnan
Ranch Hand

Joined: Jan 04, 2001
Posts: 71
You have to get the Java Mail(javamail-1.1.3), Java Activation (jaf-1.0.1) an pop3.1.1.1( if you want to receive mails) API's from sun's site. After extraction add the executable jar files mail.jar,activation.jar and pop3.jar(this depends) in your CLASSPATH. Now you need an SMTP to send the mail. Ask you ISP for this. Most cases it will be somthing like "smtp-server" followed by ".your isp domain name" . If you have you own SMTP server with a registered domain you can use that as well. This will do the job.
I'm attaching a sample code here using servlets. It will be pretty same thing for JSP's. Just FYI , for sending attachments you have to use MultiMimePart class which comes along with Java Mail.This is not included in this sample but i can send you one if you want to.
import java.util.Properties;
import javax.mail.* ;
import javax.mail.internet.* ;
import javax.servlet.*;
import javax.servlet.http.*;
public class WapMail extends HttpServlet

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
String host = "";
String from = "";
String to = "";
String subject = "Test mail";
StringBuffer text = new StringBuffer();

text.append("Test mail on WAP");

Properties props = System.getProperties();
props.put("", host);
Session session = Session.getInstance(props, null);


MimeMessage message = new MimeMessage(session);

message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));


Wml wml = new Wml();
wml.addCard("success", "success");
wml.println("<p align=\"center\">" + "Hello!" + "</p>");
wml.outputWML(response, false);
catch(Exception e)

I agree. Here's the link:
subject: Java Mail API & JSP
jQuery in Action, 3rd edition