
July 5th, 2001, 10:53 AM
|
|
Junior Member
|
|
Join Date: Jul 2001
Posts: 0
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Send email with attachement
I'm working on a script base on the example written on :
URL
but i cannot set parameter on it !
could you help me ?
i made a .jsp file.
and the info arrive with a form
code :
<%@ page import="java.util.Properties" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<%public class SendEmailWithAttachement {
public static void main (String args[])
throws Exception {
String host = args[0];
String from = args[1];
String to = args[2];
String fileAttachment = args[3];
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mpfrlinuxsmtp.mp.fr", host);
// Get session
Session session =
Session.getInstance(props, null);
// Define message
MimeMessage message =
new MimeMessage(session);
message.setFrom(
new InternetAddress(from));
message.addRecipient(
Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject(
subject);
// create the message part
MimeBodyPart messageBodyPart =
new MimeBodyPart();
//fill message
messageBodyPart.setText("body");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source =
new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler(
new DataHandler(source));
messageBodyPart.setFileName(fileAttachment);
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send( message );
}
}
%>
see something ??
|