-
JSP (
http://www.daniweb.com/forums/forum24.html)
- -
sending email (
http://www.daniweb.com/forums/thread114279.html)
| Praveeninfotech | Mar 16th, 2008 11:38 pm | |
| sending email hi,
i want to send e-mail using jsp. when i run my code no error is shown but the message is not
sent to email address.
here is the code
<html>
<body>
<form method=post action="aa.jsp" >
sender<input type=text name=text1><br>
Reciever<input type=text name=text2><br>
Subject<input type=text name=text3><br>
Message<textarea name='area1' rows=5 cols=30>
</textarea>
<input type=submit>
</form>
</body>
</html>
<%@page language="java" import="java.io.*,javax.activation.*,javax.servlet.*,javax.servlet.http.*, javax.mail.*,javax.mail.internet.*,javax.mail.event.*, java.net.*,java.util.*,com.mysql.jdbc.Driver" session="true" %>
<%
response.setContentType("text/html");
try
{
out.println("acb");
Properties props=new Properties();
props.put("mail.smtp.host", "smtp.jcom.net");
Session session1 = Session.getDefaultInstance(props,null);
String s1 = request.getParameter("text1");
String s2 = request.getParameter("text2");
out.println("acb");
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);
out.println("acb");
Transport.send(message);
out.println("acb");
out.println("mail has been sent");
}
catch(Exception ex)
{
System.out.println("ERROR....."+ex);
}
%> |
| jwenting | Mar 17th, 2008 2:14 am | |
| Re: sending email Not only are you abusing JSP for something it's not meant to be used for, but you're also eating exceptions (catching them without doing anything with them).
No wonder you don't get to see errors if you don't log them.
1) always log or otherwise handle any exception you catch
2) never use Java code in JSP
3) never use JSP for anything except displaying results to the client, use servlets instead. |
| Praveeninfotech | Mar 17th, 2008 3:40 am | |
| Re: sending email i am new to jsp so can i get the coding for sending e-mail in jsp and the steps i will have to follow.. |
| jwenting | Mar 17th, 2008 2:04 pm | |
| Re: sending email no, you can't for all the reasons I listed. |
| All times are GMT -4. The time now is 10:16 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC