1

I have a file called info.txt that is saved on my system.

And in my java code I have to modify the file name and send it as email attachment.

For example, in my code I need to create a file with the name info_myCompanyName.txt and copy contents from info.txt to info_myCompanyName.txt and email the newly created file info_myCompanyName.txt in attachment without saving it on my file system?

This is the scenario. I just want to know is it possible, if so how is it possible. I know how to copy a file from another and how to email and etc...

The Guest
  • 698
  • 11
  • 27
  • 1
    Sure this is possible. What have you tried so far? – Jim Garrison Dec 08 '15 at 22:37
  • 1
    help will be given to those who ask for it ... But this is not the right way....please show us what you have got..... yes it is possible.... – Naruto Dec 08 '15 at 22:37
  • I know that I need to show the code. But for everything we cannot show the code here sometimes. And finally I am not asking to make a program and give it to me, I want the idea. Thanks for the answers – The Guest Dec 08 '15 at 23:00

2 Answers2

2

This is a non-issue, because when you are adding an attachment to an email, you can specify the file name freely. It doesn't even matter what the original file name on your disk was.

See Sending mail attachment using Java

MimeBodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource("info.txt");
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName("info_myCompanyName.txt");
Community
  • 1
  • 1
Andreas Vogl
  • 1,776
  • 1
  • 14
  • 18
2

Sure it's possible.

...
MimeBodyPart attachFilePart = new MimeBodyPart();
FileDataSource fds = 
          new FileDataSource("info.txt");
attachFilePart.setDataHandler(new DataHandler(fds));
attachFilePart.setFileName("info_myCompanyName.txt");
...
Multipart mp = new MimeMultipart();
...
mp.addBodyPart(attachFilePart);
RealHowTo
  • 34,977
  • 11
  • 70
  • 85