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