Win a copy of Microservices Testing (Live Project) this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

FileNotFound Exception

Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am trying to send an email with attachment using html and coding is working properly when I use that in my local machine but when I upload the code on the tomcat web server it is returning error saying that messaging exception and file not found exception.Please help anybody help me out and let me know what could be the is the code I am using for sending the attachment.

<%@page import="java.util.*"%>
<%@page import="javax.mail.*"%>
<%@page import="javax.mail.internet.*,*,java.util.*,javax.mail.*,javax.activation.*"%>

String to = request.getParameter("to");
System.out.println("the recipient address is:"+to);
String from = request.getParameter("from");
String sub = request.getParameter("subject");
String msg = request.getParameter("message");
String Attachment = request.getParameter("filename");
System.out.println("This is the file name"+Attachment);
System.out.println("this is from send mail:"+to + from + sub +msg);
Properties props = new Properties();
props.put("", "smtpgateway");

Session s = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(s);
StringTokenizer st = new StringTokenizer(to, ",");
int tokenCount = st.countTokens();
System.out.println("no.of receipients:"+tokenCount);
InternetAddress [] recipientList = new InternetAddress[tokenCount];
for (int i = 0; st.hasMoreTokens(); i++)
String msgTo = st.nextToken();
System.out.println("the recipients address is:"+msgTo);
recipientList[i]= new InternetAddress(msgTo);
message.addRecipient(Message.RecipientType.TO,new InternetAddress(msgTo));
message.setFrom(new InternetAddress(from));
if(Attachment !="")
System.out.println("entered in to the if");
Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
FileDataSource fds = new FileDataSource(Attachment);
mbp.setDataHandler(new DataHandler(fds));
// Add the Multipart to the message
// Set the Date: header
message.setSentDate(new Date());

// Send the message;

[ December 23, 2008: Message edited by: Anna Anna ]
Posts: 27285
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"anna anna", please check your private messages about an important administrative matter.

As for your question:

That isn't the right way to see if the contents of two Strings are the same. Do this instead:

Also, this variable does contain the name of a file on your server, doesn't it? Because if the user enters the name of a file on their computer, you won't be able to send that file from your server code. You don't have access to the user's computer.
Posts: 67650
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
Posts: 2856
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"AnnaVA" please see your private messages again.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic