Folks,
I am using java mail to send out file attachments. A code snippet is:
-----------
String attachmentPath = "C:\temp\MyFile.txt";
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(attachmentPath);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(attachmentPath);
-----------
But when the file arrives in the email and the user tries to save it, the file name that is
presented is a munged version of the full path. e.g. "c--temp-MyFile.txt"
I would like the email client to present simply "MyFile.txt".
Is there anyway I can achieve this?
TIA -Adam
voorth - 21 May 2007 12:29 GMT
> But when the file arrives in the email and the user tries to save it, the file name that is
> presented is a munged version of the full path. e.g. "c--temp-MyFile.txt"
[quoted text clipped - 3 lines]
>
> TIA -Adam
In this case, you need the specific behaviour for FileDataSource:
-----------
String attachmentPath = "C:\temp\MyFile.txt";
messageBodyPart = new MimeBodyPart();
FileDataSource source = new FileDataSource(attachmentPath);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(source.getFile().getName());
-----------