sending email

Reply

Join Date: Mar 2008
Posts: 2
Reputation: Praveeninfotech is an unknown quantity at this point 
Solved Threads: 0
Praveeninfotech Praveeninfotech is offline Offline
Newbie Poster

sending email

 
0
  #1
Mar 16th, 2008
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
  1. <html>
  2.  
  3. <body>
  4.  
  5. <form method=post action="aa.jsp" >
  6.  
  7. sender<input type=text name=text1><br>
  8. Reciever<input type=text name=text2><br>
  9. Subject<input type=text name=text3><br>
  10. Message<textarea name='area1' rows=5 cols=30>
  11. </textarea>
  12. <input type=submit>
  13.  
  14. </form>
  15.  
  16. </body>
  17.  
  18. </html>
  19. <%@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" %>
  20. <%
  21.  
  22. response.setContentType("text/html");
  23.  
  24. try
  25.  
  26. {
  27. out.println("acb");
  28. Properties props=new Properties();
  29.  
  30. props.put("mail.smtp.host", "smtp.jcom.net");
  31.  
  32.  
  33.  
  34.  
  35.  
  36. Session session1 = Session.getDefaultInstance(props,null);
  37.  
  38. String s1 = request.getParameter("text1");
  39.  
  40. String s2 = request.getParameter("text2");
  41. out.println("acb");
  42. String s3 = request.getParameter("text3");
  43.  
  44. String s4 = request.getParameter("area1");
  45.  
  46. Message message =new MimeMessage(session1);
  47.  
  48. message.setFrom(new InternetAddress(s1));
  49.  
  50. message.setRecipients
  51.  
  52. (Message.RecipientType.TO,InternetAddress.parse(s2,false));
  53.  
  54. message.setSubject(s3);
  55.  
  56. message.setText(s4);
  57. out.println("acb");
  58. Transport.send(message);
  59.  
  60. out.println("acb");
  61. out.println("mail has been sent");
  62.  
  63. }
  64.  
  65. catch(Exception ex)
  66.  
  67. {
  68.  
  69. System.out.println("ERROR....."+ex);
  70.  
  71. }
  72.  
  73. %>
Last edited by peter_budo; Mar 17th, 2008 at 10:50 pm. Reason: Code tags are [code] not <code> :-)
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: sending email

 
0
  #2
Mar 17th, 2008
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 2
Reputation: Praveeninfotech is an unknown quantity at this point 
Solved Threads: 0
Praveeninfotech Praveeninfotech is offline Offline
Newbie Poster

Re: sending email

 
0
  #3
Mar 17th, 2008
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..
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: sending email

 
0
  #4
Mar 17th, 2008
no, you can't for all the reasons I listed.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC