How can I delete an attachment file after Transport.send()?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, March 22, 2001 09:16 AM

I am calling an external application (HTMLDOC from ) to programmatically convert an HTML file to a PDF file. Then I attach this PDF file (and other files) to my JavaMail message using a loop on all the "parts" of the Mime multi-part message. (See code snippet below) The combination of files forces me to use the URL class since some files are located on a web server while others are located locally or over an intranet. After my code calls Transport.send(msg), all subsequent calls to the File class that refer to the PDF file tell me that the file cannot be deleted. I suspect that JavaMail is not ever releasing the file until sometime later. However, I cannot determine when that    More>>


I am calling an external application (HTMLDOC from ) to programmatically convert an HTML file to a PDF file.




Then I attach this PDF file (and other files) to my JavaMail message using a loop on all the "parts" of the Mime multi-part message. (See code snippet below) The combination of files forces me to use the URL class since some files are located on a web server while others are located locally or over an intranet.




After my code calls Transport.send(msg), all subsequent calls to the File class that refer to the PDF file tell me that the file cannot be deleted.




I suspect that JavaMail is not ever releasing the file until sometime later. However, I cannot determine when that "later" time is. I have tried using an independent thread to delete the file to no avail. Even though the JavaMail object goes out of scope (I think), and I actually receive the email with the PDF attachment, myFile.delete() still returns false (while myFile.exists() and myFile.canwrite() return true).
When I stop my JBuilder test run (meaning my JVM stops) I can manually delete the file with no problem. If I manually attempt to delete the file while my asynchronous deletion thread is running and I suppose JavaMail still has "blocked" the file, I get a sharing violation from Windows2000.




Can someone give me any suggestions on when and how I can delete the file?




Thanks!


- Marco A.
mgonzalez@yfu.org

-----------------
			
// Code snippet...

Message msg = new MimeMessage(session);
int part;
URL curURL;
MimeBodyPart[] mbp;
Multipart mp = new MimeMultipart();

// inside loop on "part"
try {
curURL = new URL(filename);
}
catch (MalformedURLException badURL){}

mbp[part].setDataHandler(new DataHandler(curURL));

mp.addBodyPart(mbp[part]);
   <<Less
About | Sitemap | Contact