Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/10/2013, 10:15
Dexterminio
 
Fecha de Ingreso: septiembre-2013
Mensajes: 37
Antigüedad: 10 años, 7 meses
Puntos: 1
algun ejemplo del uso de javaweb netbeans con jsp

Hola amigos del web!

Estoy intentando enviar los valores de un formulario.jsp a un correo electrónico usando javaweb pero no me sale, checando en internet encontré este código pero me marca como resultado false y al momento de limpiar y construir el proyecto me marca que no se puede eliminar el web-inf/lib/mail.jar.

alguien que me pueda orientar pliss, si tienen algún ejemplo del envio de un formulario por correo usando jsp se los agradecería mucho, seguire investigando.

dejo el código para una clase en java

Código Java:
Ver original
  1. package enviarFormulario;
  2.  
  3. import java.util.Properties;
  4. import java.util.Date;
  5. import javax.mail.Session;
  6. import javax.mail.Message;
  7. import javax.mail.Transport;
  8. import javax.mail.internet.MimeMultipart;
  9. import javax.mail.internet.MimeMessage;
  10. import javax.mail.internet.MimeBodyPart;
  11. import javax.mail.internet.InternetAddress;
  12.  
  13. public class MailSender {
  14.  
  15.     public MailSender() {
  16.     }
  17.  
  18.     public static boolean send(String hostSmtp, String senderAddress, String toAddress,
  19.             String ccAddress, String bccAddress, String subject,
  20.             boolean isHTMLFormat, StringBuffer body, boolean debug) {
  21.  
  22.         MimeMultipart multipart = new MimeMultipart();
  23.  
  24.         Properties properties = new Properties();
  25.  
  26.         properties.put("mail.smtp.host", hostSmtp);
  27.         Session session = Session.getDefaultInstance(properties, null);
  28.         session.setDebug(debug);
  29.         try {
  30.             MimeMessage msg = new MimeMessage(session);
  31.             msg.setFrom(new InternetAddress(senderAddress));
  32.             msg.setRecipients(Message.RecipientType.TO, toAddress);
  33.             msg.setRecipients(Message.RecipientType.CC, ccAddress);
  34.             msg.setRecipients(Message.RecipientType.BCC, bccAddress);
  35.             msg.setSubject(subject);
  36.             msg.setSentDate(new Date());
  37.  
  38.             // BODY
  39.             MimeBodyPart mbp = new MimeBodyPart();
  40.             if (isHTMLFormat) {
  41.                 mbp.setContent(body.toString(), "text/html");
  42.             } else {
  43.                 mbp.setText(body.toString());
  44.             }
  45.  
  46.             multipart.addBodyPart(mbp);
  47.  
  48.             msg.setContent(multipart);
  49.             Transport.send(msg);
  50.         } catch (Exception mex) {
  51.             System.out.println(">> MailSender.send() error = " + mex);
  52.             return false;
  53.         }
  54.         return true;
  55.     }
  56. }


código para el *.jsp

Código Java:
Ver original
  1. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  2. <!DOCTYPE html>
  3.  
  4. <%@ page language="java" %>
  5.  <%@ page import = "enviarFormulario.MailSender"%>
  6.  <%
  7.  MailSender ms = new MailSender();
  8.  
  9.  boolean result = ms.send("smtp.dominio.com","[email protected]",
  10.  "mail de prueba", false, new StringBuffer("hola"),true);
  11.  
  12.  out.print("Resultado del envío del mensaje : " + result);
  13.  %>