S.O. Win Xp
Apache Tomcat
Mysql
JavaMail
Drinkweaver
Esta vez se trata de una jsp que envia un email con un attachment del archivo de excel que creamos con POI.
Código PHP:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.util.Properties" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<%@ page import="java.io.*" %>
<%@ page import="javax.servlet.http.HttpServletRequest"%>
<%@ page import="javax.servlet.http.*"%>
<%
try {
String to = "ko^ke@forosdelweb, ko^[email protected]";
String from = "ko^[email protected]";
String host = "swishmail.com"; //aqui va tu host que puede ser una ip
String filename = "C:\\tomcat5\\jakarta-tomcat-5.0.27\\webapps\\ROOT\\sms\\workbook.xls"; //enviamos el archivo que generamos en excell con POI ;-)
//boolean debug = Boolean.valueOf(args[4]).booleanValue();
String msgText1 = "Sending a file";
String subject = "Sending a file";
// create some properties and get the default Session
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session1 = Session.getInstance(props, null);
// session1.setDebug(debug);
// create a message
MimeMessage msg = new MimeMessage(session1);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(msgText1);
// create the second message part
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds = new FileDataSource(filename);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
String ruta = request.getServletPath();
%>
<%=ruta%>
<%
// create the Multipart and add its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
// set the Date: header
// msg.setSentDate(new Date());
// send the message
Transport.send(msg);
} catch (Exception ex) {ex.printStackTrace();}
%>
<!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>::::</title>
</head>
<body>
email enviado con exito
</body>
</html>