Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending Mail JSP

 
Dean Chester
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I found this on the web so i thought i could change the code to send emails for when new users register yet this example code doesn't work

This is on the index page thats why the link just reloads the index page.
The error i got was this:
An error occurred at line: 17 in the jsp file: /index.jsp
Session cannot be resolved to a type
14: Properties props = new Properties();
15: props.put("mail.smtp.host", "mail.example.com");
16:
17: Session s = Session.getInstance(props, null);
18: MimeMessage message = new MimeMessage(s);
19:
20: try {

Has Anyone got a solution? Or know of an easier way of getting emails sent via a JSP/servlet. BTW I did change the SMTP server and the email addresses yet changed them for the purpose of showing you my code.
Thanks in Advance
Dean
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64837
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After recovering from seeing so much wretched Java in a JSP, I ask, is Session a valid implicit variable?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dean,
This line is a problem.


Session is an implicit variable in the JSP. It is not a type. You could say new MimeMessage(s);. Or HttpSession s = Session....

Also, I hope you are just using this to experiment. The mail code should be in a Java class.
 
Dean Chester
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Dean,
This line is a problem.


Session is an implicit variable in the JSP. It is not a type. You could say new MimeMessage(s);. Or HttpSession s = Session....

Also, I hope you are just using this to experiment. The mail code should be in a Java class.


Yes i know that i can put this in my servlet of anything that i'm writing i am just interested in getting something so it will email people for registration purposes.
Dean
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dean Chester wrote:Yes i know that i can put this in my servlet of anything that i'm writing i am just interested in getting something so it will email people for registration purposes.


Good. Then put it in a servlet so that your code doesn't get tangled up with implicit JSP variables.

Actually it would be better to test it in a plain old Java application first, to get it working, before putting it into a servlet. Servlets are not the most convenient of test platforms.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chester, the problem is not with Session. I agree that session is an implicit variable in jsp. But it is case sensitive. Here you are using Session instead of session. So the problem is not with the Session. You are missing something. I think you are missing Transport class.


 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds as if you don't have the mail.jar file from the JavaMail distribution in the WEB-INF/lib directory of your web app.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic