Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/07/2010, 08:48
gioropu
 
Fecha de Ingreso: noviembre-2009
Mensajes: 31
Antigüedad: 14 años, 5 meses
Puntos: 1
enviar mails usando jsp

Hola, tengo que enviar correos desde una aplicacion utilizando jsp y para empezar estoy probando un ejemplo que he encotrado en internet.

Para ello necesito los archivos mail.jar y activation.jar; los códigos son los siguientes:

1º mailAPI.jsp
Código PHP:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    
pageEncoding="ISO-8859-1"%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<
title>Mail API</title>
</
head>
<
body>
<
table border="1" width="50%"  cellpadding="0" cellspacing="0">
<
tr>
<
td width="100%">
<
form method="POST" action="mail.jsp">
<
table border="1" width="100%" cellpadding="0" cellspacing="0">
<
h1>Mail API</h1>
<
tr>
<
td width="50%"><b>To:</b></td>
<
td width="50%"><input type="text" name="to" size="30"></td>
</
tr>
<
tr>
<
td width="50%"><b>From:</b></td>
<
td width="50%"><input type="text" name="from" size="30"></td>
</
tr>
<
tr>
<
td width="50%"><b>Subject:</b></td>
<
td width="50%"><input type="text" name="subject" size="30"></td>
</
tr>
<
tr>
<
td width="50%"><b>Description:</b></td>
<
td width="50%"><textarea name="description" type="text"
cols="40" rows="15" size=100>
</
textarea>
</
td>
</
tr>
<
tr>
<
td><p><input type="submit" value="Send Mail" name="sendMail"></td>
</
tr>
</
table>
</
p>
</
form>
</
td>
</
tr>
</
table>
</
body>
</
html
2º mail.jsp
Código PHP:
<%@ page language="java" import "javax.naming.*,  java.io.*,javax.mail.*,javax.mail.internet.*,com.sun.mail.smtp.*" contentType="text/html; charset=ISO-8859-1"
    
pageEncoding="ISO-8859-1"%>    
<!
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<
title>Mail</title
</
head>
<
body>
<%
try{
    
Session mailSession Session.getInstance(System.getProperties());    
    
Transport transport= new SMTPTransport(mailSession,new        URLName("localhost"));
    
transport.connect("localhost",25,null,null);    
    
MimeMessage m= new MimeMessage(mailSession);
    
m.setFrom(new InternetAddress(%><%request.getParameter("from")%><%));
    
Address[] toAddr = new InternetAddress[] {
            new 
InternetAddress(%><%request.getParameter("to")%><%)
        };
    
m.setRecipients(javax.mail.Message.RecipientType.TO,toAddr);
    
m.setSubject(%><%request.getParameter("subject")%><%);
    
m.setSentDate(new java.util.Date());
    
m.setContent(%><%request.getParameter("description")%><%, "text/plain");
    
transport.sendMessage(m,m.getAllRecipients());
    
transport.close();
    
out.println("Thanks for sending mail!");
}
catch(
Exception e){
    
out.println(e.getMessage());
    
e.printStackTrace();
}
%>
</
body>
</
html
Lo que me muestra el navegador es lo siguiente: "Could not connect to SMTP host: localhost, port: 25";

No tengo mucha idea sobre ello, pero es que estoy intentando saber cual es mi servidor de correo saliente para ponerlo en el código si va por ahí el fallo. Si alguién puede echarme un cable...gracias.

Salu2