Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending mails

 
sajeev JS
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ravi Shankar
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
}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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic