wood burning stoves 2.0*
The moose likes Java in General and the fly likes Error in Sending Attachments using jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Error in Sending Attachments using jsp " Watch "Error in Sending Attachments using jsp " New topic
Author

Error in Sending Attachments using jsp

bansal_amit
Greenhorn

Joined: May 01, 2001
Posts: 3
hi all,
i need help for coding for attachments in JSP
i had tried the following code
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@ page import="java.io.IOException"
@ page import="java.util.Properties"
@ page import="java.util.Date"
@ page import="javax.mail.*"
@ page import="javax.mail.internet.*"
@ page import="javax.servlet.*"
@ page import="javax.servlet.http.*"
@ page import="javax.activation.*"
@ page import="java.io.*"
@ page import="java.net.*"
String to="amit_bansal00@yahoo.com";
String subject="Hi";
String matter="India is great";
String from="amit_bansal00@sify.com";
String file="c:/sendmail.txt";
String host="mail.domain.com";
try{
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
boolean sessionDebug=false;
Session mailSession=Session.getDefaultInstance(props, null);
mailSession.setDebug(sessionDebug);
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
MimeMultipart mp = new MimeMultipart();
mp.setSubType("related");
MimeBodyPart mbp1= new MimeBodyPart();
mbp1.setText(matter); // Type your Text Message Here
MimeBodyPart mbp2 = new MimeBodyPart();
FileDataSource fds = new FileDataSource(file);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
mp.addBodyPart(mbp1); // mail body of the message
mp.addBodyPart(mbp2); // Add your attachments here
message.setContent(mp);
message.setSentDate(new Date());
Transport.send(message);
}
catch(Exception e){}
When i execute this code I am getting FileNotFoundException because of it is not taking Attach file. And at that c:\sendmail.txt exists in my system and the code is working properly when i dont include attachment part . I am not able to find out where the problem is so pls guide me where is the error in my code .
Expecting ur reply at the earliest
Regards
Amit Bansal

------------------
lakshmipathy Narayan
Greenhorn

Joined: Apr 25, 2001
Posts: 4
Hi,
I think there is nothing wrong in the code.I tested it with Lotus
Server and the mail was delivered with the attachment.My guess is, something wrong with the mail server
Pathy
Sean MacLean
author
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
"bansal_amit",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Error in Sending Attachments using jsp
 
Similar Threads
Problem in Mail Attachemnt using JSP
Java Mail Attachments
Error in sending attachment in JSP
Error in sending attachments in JSP
Sending mail through Exchange Server