Hi,
I am trying to send mail with attachment, but i cant do this.
Below is my code, Can someone tell me what is wrong with it??
simple.jsp:
<%
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.quicknet.nl");
Session s = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("you@example.com");
message.setFrom(from);
String toAddress = request.getParameter("to");
InternetAddress to = new InternetAddress(toAddress);
message.addRecipient(Message.RecipientType.TO, to);
String subject = request.getParameter("subject");
message.setSubject(subject);
String text = request.getParameter("text");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("Pardon Ideas");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send(message);
email.html
<html>
<head><title>S</title></head>
<body>
<p align="center"><b>A custom email utility.</b></p>
<form action="simple.jsp" method="post" ENCTYPE="multipart/form-data" >
<table align="center">
<tr><td>To</td><td><input name="to" size="50" /></td></tr>
<tr><td>Subject</td><td>
<input name="subject" size="50" value="[JavaMail Example - ]"/>
</td></tr>
<tr><td colspan="2">
<textarea name="text" cols="50" rows="20">Hello from JavaMail!</textarea>
<INPUT TYPE="file" NAME="thefile">
</td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Send Email"/></td></tr>
</table>
</form>
</body>
</html>
Please help
I am trying to send mail with attachment, but i cant do this.
Below is my code, Can someone tell me what is wrong with it??
simple.jsp:
<%
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.quicknet.nl");
Session s = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("you@example.com");
message.setFrom(from);
String toAddress = request.getParameter("to");
InternetAddress to = new InternetAddress(toAddress);
message.addRecipient(Message.RecipientType.TO, to);
String subject = request.getParameter("subject");
message.setSubject(subject);
String text = request.getParameter("text");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setText("Pardon Ideas");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// Send the message
Transport.send(message);
email.html
<html>
<head><title>S</title></head>
<body>
<p align="center"><b>A custom email utility.</b></p>
<form action="simple.jsp" method="post" ENCTYPE="multipart/form-data" >
<table align="center">
<tr><td>To</td><td><input name="to" size="50" /></td></tr>
<tr><td>Subject</td><td>
<input name="subject" size="50" value="[JavaMail Example - ]"/>
</td></tr>
<tr><td colspan="2">
<textarea name="text" cols="50" rows="20">Hello from JavaMail!</textarea>
<INPUT TYPE="file" NAME="thefile">
</td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Send Email"/></td></tr>
</table>
</form>
</body>
</html>
Please help