Hi,
Sending Email using JavaMail API. When sending mail direct via class it
works fine but When sending via jsp page using weblogic as Application
Server it produces error and not sending/forwarding mail.
The code + Error is as follows. Anyone's help will be appreciated:
CODE ---------------------------
<%@ page
import="java.net.*,java.util.*,java.io.*,javax.mail.Transport,javax.mail.Mes
sage,javax.mail.*,javax.mail.internet.*,javax.activation.*" %>
<%
String msgText = "This is a message body.\nHere's the second line.";
String msgText2 = "\nThis was sent by transport.java demo program.";
String to = "[EMAIL PROTECTED]";
String from = "[EMAIL PROTECTED]";
String subject = " This is test from JSP Page .... ";
String body = "Hello its the body of mail ............ ";
InternetAddress[] addrs = null;
Address[] addrs2 = null;
String host = "mail.visualsoft-inc.com";
int port = 25;
boolean debug = false;
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", host);
if (debug)
props.put("mail.debug", "true");
out.print("<br> value of prop host = "+props.get("mail.smtp.host"));
javax.mail.Session s2 =
javax.mail.Session.getDefaultInstance(props,null);
out.println("<BR>Here is the valuse"+s2.toString()+"<br>");
//s2.setDebug(debug);
//Session s2=new Session();
Message msg = null;
try {
// create a message
msg = new MimeMessage(s2);
}
catch (Exception mex)
{
out.print("<br>msg not created...........<br>"+
mex.toString());
}
try {
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setContent(msgText, "text/plain");
}
catch (Exception mex)
{
out.print("<br>msg not create for values...........<br>" +
mex.toString());
}
try {
Transport.send(msg);
out.print("<br>mail has been sent ...........<br>");
}
catch(SendFailedException exp)
{ out.print("<br> <b>Exception Mail not sent : <br>"+exp
+"</b>");
}
catch (Exception mex)
{
out.print("<br>mail has NOT been sent ...........<br>"+
mex.toString());
}
%>
---------------------------------
ERROR --------------
Exception Mail not sent :
javax.mail.SendFailedException: Sending failed; nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: 192.168.0.22,
port: 25; nested exception is: java.net.ConnectException: Connection
refused: no further information
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets