Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Mail API & JSP

 
elavazhagan selvaraj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where can I get pop3 server , IMAP server and IMAP server for testing purpose ??
thanks
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on your ISP at home, or your hosting company at work.
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an introduction to JSP AND JAVAMAIL in:
  http://www.jspinsider.com/tutorials/jsp/javamail/JSPJavaMail_intro.html

 
Ajan Balakrishnan
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic