File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Java Mail API & JSP

elavazhagan selvaraj
Greenhorn

Joined: Jan 23, 2001
Posts: 5
hello,
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
codes.

regards,
elavazhagan


Elavazhagan Selvaraj<BR>elavazhagan@rediffmail.com
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 ??
thanks
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
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
There is an introduction to JSP AND JAVAMAIL in:
  http://www.jspinsider.com/tutorials/jsp/javamail/JSPJavaMail_intro.html



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.io.IOException;
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 = "smtp-server.nc.rr.com";
String from = "abalakrishnan@nc.rr.com";
String to = "ajanb@hotmail.com";
String subject = "Test mail";
StringBuffer text = new StringBuffer();

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

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

session.setDebug(false);

MimeMessage message = new MimeMessage(session);

message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
message.setText(text.toString());

Transport.send(message);

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

Ajan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Mail API & JSP