Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

How to set attachment name with JavaMail

Thread view: 
Adam Lipscombe - 21 May 2007 09:51 GMT
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());
-----------


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.