This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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: 67164
169
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: 38911
686
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: 23873
50
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!