Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Sending Mail JSP  RSS feed

 
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
 
Author and ninkuma
Marshal
Posts: 66789
168
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?
 
author & internet detective
Marshal
Posts: 38508
653
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
 
Sheriff
Posts: 23649
49
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.
 
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.


 
Rancher
Posts: 42975
76
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!