aspose file tools*
The moose likes JSP and the fly likes Sending Mail JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Sending Mail JSP" Watch "Sending Mail JSP" New topic
Author

Sending Mail JSP

Dean Chester
Ranch Hand

Joined: Jul 26, 2009
Posts: 31
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

Joined: Jan 10, 2002
Posts: 61218
    
  66

After recovering from seeing so much wretched Java in a JSP, I ask, is Session a valid implicit variable?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Dean Chester
Ranch Hand

Joined: Jul 26, 2009
Posts: 31
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Sep 15, 2009
Posts: 806

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.




Love all, trust a few, do wrong to none.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending Mail JSP