This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Error in sending attachment in JSP  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i need help for coding for attachments in JSP
i had tried the following code
@ page import=""
@ 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="*"
@ page import="*"
String to="";
String subject="Hi";
String matter="India is great";
String from="";
String file="c:/sendmail.txt";
String host="";
Properties props = System.getProperties();
props.put("", host);
props.put("mail.transport.protocol", "smtp");
boolean sessionDebug=false;
Session mailSession=Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
MimeMultipart mp = new MimeMultipart();
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));
mp.addBodyPart(mbp1); // mail body of the message
mp.addBodyPart(mbp2); // Add your attachments here
message.setSentDate(new Date());
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
Amit Bansal

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!