www.StudyJava.org

Pure Java

It is currently Wed Sep 08, 2010 11:44 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Sending mails in JSP / apache / tomcat
PostPosted: Sat May 23, 2009 2:57 pm 
Offline

Joined: Sat May 23, 2009 2:44 pm
Posts: 3
Hi All,

I am looking for a solution to sending mails through JSP. please give ur suggestions...
Which solution i need to choose java mail based or the apache sendmail or any other ?
which one is stable and easy to maintain? Please provide needed links also........
Thanks in adv....


 
 Profile  
 
 Post subject: Re: Sending mails in JSP / apache / tomcat
PostPosted: Sat May 23, 2009 3:03 pm 
Offline

Joined: Sat Apr 21, 2007 10:21 am
Posts: 116
are u looking for code in JSP or in java as Java beans ??


 
 Profile  
 
 Post subject: Re: Sending mails in JSP / apache / tomcat
PostPosted: Sat May 23, 2009 3:07 pm 
Offline

Joined: Sat May 23, 2009 2:44 pm
Posts: 3
JSP will be fine, if it is working with tomcat with out much trouble java code also do but pls tell me how to integrate that with jsp...thnx


 
 Profile  
 
 Post subject: Re: Sending mails in JSP / apache / tomcat
PostPosted: Sat May 23, 2009 3:08 pm 
Offline

Joined: Sat Apr 21, 2007 10:21 am
Posts: 116
<html>
<head>
<title>JSP JavaMail Example </title>
</head>
<body>
<%@ page import="java.util.*" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<%
String host = "yourmailhost";
String to = request.getParameter("to");
String from = request.getParameter("from");
String subject = request.getParameter("subject");
String messageText = request.getParameter("body");
boolean sessionDebug = false;
// Create some properties and get the default Session.
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);

// Set debug on the Session
// Passing false will not echo debug info, and passing True will.

mailSession.setDebug(sessionDebug);

// Instantiate a new MimeMessage and fill it with the
// required information.

Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);

// Hand the message to the default transport service
// for delivery.

Transport.send(msg);
out.println("Mail was sent to " + to);
out.println(" from " + from);
out.println(" using host " + host + ".");
%>
</table>
</body>
</html>


 
 Profile  
 
 Post subject: Re: Sending mails in JSP / apache / tomcat
PostPosted: Sat May 23, 2009 3:14 pm 
Offline

Joined: Sat May 23, 2009 2:44 pm
Posts: 3
Thank you bobit79...

Do you know the sendmail config ....pls post that too..


 
 Profile  
 
 Post subject: Re: Sending mails in JSP / apache / tomcat
PostPosted: Sat May 23, 2009 3:18 pm 
Offline

Joined: Sat Apr 21, 2007 10:21 am
Posts: 116
create a form with ("to");
("from");
("subject");
("body");

text fileds


 
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Google
 




Powered by phpBB © 2002, 2006 phpBB Group
[ Time : 0.048s | 12 Queries | GZIP : Off ]