dcsimg

When sending an attachment with JavaMail, I don't want the attachment to have the full directory path from the source. How do I shorten the name associated with the attachment?

John Zukowski

The MimeBodyPart class has a setFileName() method that allows you to specify any text you want. Just set it to the name of the FileDataSource:

MimeBodyPart mbp = new MimeBodyPart();
FileDataSource fds = 
  new FileDataSource("c:/temp/foo.jpg");
mbp.setFileName(fds.getName());