help configuring a mail server for use with mail.jar and activation.jar

Posted by bobbyblue on Stack Overflow See other posts from Stack Overflow or by bobbyblue
Published on 2010-06-02T11:41:10Z Indexed on 2010/06/02 11:43 UTC
Read the original article Hit count: 185

Filed under:
|
|
|
|

im trying to work with the below code:

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import javax.mail.*;

import javax.mail.internet.*; // important

import javax.mail.event.*; // important

import java.net.*;

import java.util.*;

public class servletmail extends HttpServlet

{

public  void doPost(HttpServletRequest request,HttpServletResponse response)

                              throws ServletException, IOException

{

    PrintWriter out=response.getWriter();

    response.setContentType("text/html");

    try

    {

       Properties props=new Properties();

       props.put("mail.smtp.host","localhost");   //  'localhost' for testing

Session session1 = Session.getDefaultInstance(props,null);

       String s1 = request.getParameter("text1"); //sender (from)

       String s2 = request.getParameter("text2");

       String s3 = request.getParameter("text3");

       String s4 = request.getParameter("area1");

 Message message =new MimeMessage(session1);

  message.setFrom(new InternetAddress(s1));

  message.setRecipients

          (Message.RecipientType.TO,InternetAddress.parse(s2,false));

       message.setSubject(s3);

       message.setText(s4);        

       Transport.send(message);

       out.println("mail has been sent");

    }

    catch(Exception ex)

    {

       System.out.println("ERROR....."+ex);

    }

}

}

im using mail.jar and activation.jar

but i cant understand how shouls i configure it with a mail server

which mail server should i use

will i be able to send an email using above what are the requirements a mail server? how should i configure it

© Stack Overflow or respective owner

Related posts about java

Related posts about mysql