How to send email from my application to another sites?

hi guys , I need to send email to the inbox of a particular email id.In my application I have the email id of the employees.The email should automatically go to an employee's inbox when ever the manager sanctions his leave.Please, give me the details and the source codes as well.
[288 byte] By [Vinodbhai@suna] at [2007-11-27 4:48:08]
# 1
You need to use JavaMail and there's really no big deal in using it. Here's a nice tutorial: http://java.sun.com/developer/onlineTraining/JavaMail/contents.html
Dalzhima at 2007-7-12 10:00:58 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks a lot.
Vinodbhai@suna at 2007-7-12 10:00:58 > top of Java-index,Java Essentials,Java Programming...
# 3

Hi i am attaching the code here

this is class file which you have to put in ur class package of web inf

import java.io.IOException;

import java.io.PrintWriter;

import javax.mail.Message;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.servlet.RequestDispatcher;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class SendMailServlet extends HttpServlet {

public void doPost(HttpServletRequest request,

HttpServletResponse response)

throws IOException, ServletException

{

// Acquire request parameters we need

String from = request.getParameter("mailfrom");

String to = request.getParameter("mailto");

String subject = request.getParameter("mailsubject");

String content = request.getParameter("mailcontent");

if ((from == null) || (to == null) ||

(subject == null) || (content == null)) {

RequestDispatcher rd =

getServletContext().getRequestDispatcher("/jsp/mail/sendmail.jsp");

rd.forward(request, response);

return;

}

// Prepare the beginning of our response

PrintWriter writer = response.getWriter();

response.setContentType("text/html");

writer.println("<html>");

writer.println("<head>");

writer.println("<title>Example Mail Sending Results</title>");

writer.println("</head>");

writer.println("<body bgcolor=\"white\">");

try {

// Acquire our JavaMail session object

Context initCtx = new InitialContext();

Context envCtx = (Context) initCtx.lookup("java:comp/env");

Session session = (Session) envCtx.lookup("mail/Session");

// Prepare our mail message

Message message = new MimeMessage(session);

message.setFrom(new InternetAddress(from));

InternetAddress dests[] = new InternetAddress[]

{ new InternetAddress(to) };

message.setRecipients(Message.RecipientType.TO, dests);

message.setSubject(subject);

message.setContent(content, "text/plain");

// Send our mail message

Transport.send(message);

// Report success

writer.println("<strong>Message successfully sent!</strong>");

} catch (Throwable t) {

writer.println("<font color=\"red\">");

writer.println("ENCOUNTERED EXCEPTION: " + t);

writer.println("<pre>");

t.printStackTrace(writer);

writer.println("</pre>");

writer.println("</font>");

}

// Prepare the ending of our response

writer.println("

");

writer.println("<a href=\"jsp/mail/sendmail.jsp\">Create a new message</a>

");

writer.println("<a href=\"jsp/index.html\">Back to examples home</a>

");

writer.println("</body>");

writer.println("</html>");

}

}

/***********************************************************/

JSP Page will be like this

<html>

<head>

<title>Example Mail Sending Form</title>

</head>

<body bgcolor="white">

<form method="POST" action="../../SendMailServlet">

<table>

<tr>

<th align="center" colspan="2">

Enter The Email Message To Be Sent

</th>

</tr>

<tr>

<th align="right">From:</th>

<td align="left">

<input type="text" name="mailfrom" size="60">

</td>

</tr>

<tr>

<th align="right">To:</th>

<td align="left">

<input type="text" name="mailto" size="60">

</td>

</tr>

<tr>

<th align="right">Subject:</th>

<td align="left">

<input type="text" name="mailsubject" size="60">

</td>

</tr>

<tr>

<td colspan="2">

<textarea name="mailcontent" rows="10" cols="80">

</textarea>

</td>

</tr>

<tr>

<td align="right">

<input type="submit" value="Send">

</td>

<td align="left">

<input type="reset" value="Reset">

</td>

</tr>

</table>

</form>

</body>

</html>

/******************************************************?

Basic requirement for this that u should instal SMTP server on ur machine and customize the code as per your requirements.

Its working fine for me as i m using the same.

Plz dont forget your duke points

Cheers

Sandy

sandysharma2000a at 2007-7-12 10:00:58 > top of Java-index,Java Essentials,Java Programming...