How to send email using JSP and jar file ?

Status
Not open for further replies.

kmthien

Senior member
Oct 8, 2002
363
0
0
Hi,

I am developing an Intranet Leave application using JSP and JavaBean. Employee apply leave via Intranet (IE 6.0) and after applying their leave, an email will send to their boss. How to do a send email ? Thanks !!
 
Last edited by a moderator:

twilly

Senior member
May 7, 2002
216
0
0
here is something I found. I don't know JSP or java, but have done it in ASP and PHP, and it is quite simple...

Here is an article I have found for you:

Here is the link too

LINK

Advanced JSP Sample : Sending Email
Previous Contents Next


--------------------------------------------------------------------------------

OTN provides three versions of this sample: one using the Java Mail API directly in a JavaBean, one using the sendMail utility tag and one using the utility javabean oracle.jsp.webutil.email.SendMailBean.

Using JSPs and Java Mail API
Contents
Purpose
Remarks
Code from SendMail.jsp
Source Code Listings
Purpose
Send email using JSPs and Java Mail API.

Remarks
An HTML form accepts input such as email ID, subject, and message body. When the user clicks the Send button, the JSP invokes SendMailBean to send the email using the JavaMail API. The JSP gets parameter values from the HTTP request object and passes them to the send method in the SendMailBean. This 'send' method uses the JavaMail API to send the mail.

Code from SendMail.jsp
<jsp:useBean id="sendMail" class="SendMailBean" scope="page" /> <% String l_from = request.getParameter("p_from"); String l_to = request.getParameter("p_to"); String l_cc = request.getParameter("p_cc"); String l_subject = request.getParameter("p_subject"); String l_message = request.getParameter("p_message"); %> <%= sendMail.send(l_from, l_to, l_cc, l_subject, l_message) %>




Source Code Listings
SendMailBean.java
SendMail.jsp
InputsForm.jsp
Using the sendMail utility tag
Contents
Purpose
Remarks
Code from SendMail.jsp
Source Code Listings
Purpose
Send email using OC4J JSP sendMail tag in the JSPs.

Remarks
An HTML form accepts input such as email ID, subject, and message body. When the user clicks the Send button, the SendMail.jsp using the OC4J JSP sendMail tag sends an email. The SendMail.jsp gets parameter values from the HTTP request object and passes them through the sendMail tag attributes.

Code from SendMail.jsp
...

<% //Read all inputs into local variables String l_from = request.getParameter("p_from"); String l_to = request.getParameter("p_to"); String l_cc = request.getParameter("p_cc"); String l_bcc = request.getParameter("p_bcc"); String l_subject = request.getParameter("p_subject"); String l_message = request.getParameter("p_message"); String l_smtpSvr = request.getParameter("p_smtpServer"); session.setAttribute("smtpServer",l_smtpSvr); %> <%-- Use OC4J Jsp mail tag to send the mail --%> <mail:sendMail host='<%=(String)session.getValue("smtpServer")%>' sender='<%=l_from%>' recipient='<%=l_to%>' cc='<%=l_cc%>' bcc='<%=l_bcc%>' subject='<%=l_subject%>'> <%=l_message%> </mail:sendMail>...





Source Code Listings
InputsForm.jsp
SendMail.jsp
Using the utility javabean
Contents
Purpose
Remarks
Code from SendMail.jsp
Source Code Listings
Purpose
Send email using JSPs using OC4J JSP utility JavaBean.

Remarks
An HTML form accepts input such as email ID, subject, and message body. When the user clicks the Send button, the JSP invokes SendMailBean to send the email using the JavaMail API. The JSP gets parameter values from the HTTP request object and sets them in the OC4J JSP Utility JavaBean, oracle.jsp.webutil.email.SendMailBean. Then, the JSP calls the 'sendMessage' method in the Bean which sends the mail using the values set earlier.

Code from SendMail.jsp
...<jsp:useBean id="sendMail" class="oracle.jsp.webutil.email.SendMailBean"
scope="page" /><% String l_from = request.getParameter("p_from"); String l_to = request.getParameter("p_to"); String l_cc = request.getParameter("p_cc"); String l_bcc = request.getParameter("p_bcc"); String l_subject = request.getParameter("p_subject"); String l_message = request.getParameter("p_message"); String l_smtpSvr = request.getParameter("p_smtpServer"); session.setAttribute("smtpServer",l_smtpSvr);

//set the mail server host sendMail.setHost(l_smtpSvr);
//set sender address sendMail.setSender(l_from);
//set the recipient(s) sendMail.setRecipient(l_to);
//set Cc address sendMail.setCc(l_cc);

//set Bcc address sendMail.setBcc(l_bcc);
//set Subject of the email sendMail.setSubject(l_subject);

//set body of the mail sendMail.setContent(l_message);

//send the email sendMail.sendMessage(pageContext);%>...





 

kmthien

Senior member
Oct 8, 2002
363
0
0
Hi,

I am runing Tomcat 5.0.16 under Redhat 7.3 !! How ? Which one should I use ??
 

KushBhargava

Junior Member
Oct 15, 2012
2
0
0
Hi kmthien...

This post has not been activated from many years. But i also want the same thing that you want to do and i believe you must found a solution for this. So please send me the code for this application so i can use your code and even understand from the code how it works.
 

KushBhargava

Junior Member
Oct 15, 2012
2
0
0
Hi Kmthien...

I want almost similar to this. I need an application where user enter the To, Subject and Body and then when the user send it goes to the admin and there must be two buttons if admin accepts the mail send to all and if admin decline the mail it goes back to the user. If you cant provide me the code atleast help me how to solve this.
 
Status
Not open for further replies.