aspose file tools*
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
Author

Sending mails

sajeev JS
Greenhorn

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.*" %>
<%
try
{
Properties props = new Properties();
props.put("mail.smtp.host", "softron.softron.com");
Session s = Session.getInstance(props);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("sajeev@softron.softron.com");
message.setFrom(from);
InternetAddress to = new InternetAddress("aparna@softron.softron.com");
message.addRecipient(Message.RecipientType.TO, to);

message.setSubject("Test from JavaMail.");
message.setText("Hello from JavaMail!");
Transport.send(message);
}catch(Exception e)
{
}
%>
<html>
<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>
</html>
**************************************************
regards
sajeev
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
Hi Sajeev
Your "mail.smtp.host" 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.
HTH
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
Greenhorn

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)
Regards
Ravi
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12783
    
    5
}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:

Bill
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...
hth


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending mails