File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Sending mails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Sending mails" Watch "Sending mails" New topic

Sending mails

sajeev JS

Joined: May 06, 2003
Posts: 6
hai my dear friends
I am doing a jsp project and i want to send mails in it.I got code for this from net and tried it with the smtp host as my company id.But it is not working.can u pls suggest where would have went wrong.My code is given bellow.]
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
Properties props = new Properties();
props.put("", "");
Session s = Session.getInstance(props);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("");
InternetAddress to = new InternetAddress("");
message.addRecipient(Message.RecipientType.TO, to);

message.setSubject("Test from JavaMail.");
message.setText("Hello from JavaMail!");
}catch(Exception e)
<p align="center">A Message has been sent.<br>Check your inbox.</p>
<p align="center"><a href="sendmail.jsp">Click here to send another!</a></p>
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
Hi Sajeev
Your "" has got to reference a valid SMTP mail server. I suggest that you have a talk with your network/mail server administrator and find the name or IP address of a SMTP server that will allow you to use it for outgoing emails.
The rest of the code looks fine.
Andy Bowes

Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
Ravi Shankar

Joined: Apr 07, 2003
Posts: 26
Hi Sajeev
what is the version of sdk on which trying to run this code . Is it greater than 1.2?
becoz i noticed that the method getInstance(props) is supported under sdk 1.2 but it not available under sdk 1.4 it has only getInstance(java.util.Properties,Authenticator)
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
}catch(Exception e)

Its enought to make you scream with frustration
You have thrown away the information you need to solve your problem.
You should either print a stack trace or create an errorPage and have it print a stack trace.
This can be as simple as:

Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
hmmm... :roll: Hope your code works and whenever you have some time check the mailer taglib, you'll see how easy and clean is to send an email from a jsp...

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
I agree. Here's the link:
subject: Sending mails
It's not a secret anymore!