Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Python Continuous Integration and Delivery this week in the Python 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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
 
Marshal
Posts: 67239
170
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
Posts: 39148
724
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
 
Marshal
Posts: 24188
54
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: 42974
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.
 
Beauty is in the eye of the tiny ad.
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!