cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a .txt or .csv file with script and send it as Email attachment.

Former Member
0 Kudos

Hi Experts!

Is it possible to create a csv or txt file with just data (strings) and attach it to a mail?

If so, how could it be achieved?

Thanks in advance!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Oscar,

I created this example to send a txt file:

import com.sap.odp.api.util.NotificationUtil;
import com.sap.odp.api.comp.messaging.MailTypeEnumType;


Properties params = new Properties();

params.put(new String("TOKEN1"), "Token 1");

String[] recipients = {"test@gmail.com"};

sender = session.getAccount();

mailTypeEnum = new MailTypeEnumType(MailTypeEnumType.ODP_CUSTOM_TEMPLATE1);

/*String to a ByteArrayInputStream*/

String fileContent = "Test attachment 1\nTest attachment 2\nTest attachment 3\n";

InputStream inputStream = new  ByteArrayInputStream(fileContent.getBytes());

/*Send the email with the file name Test.txt*/

NotificationUtil.sendNotification(recipients,sender, mailTypeEnum,params,"FileName.txt",inputStream);

Regards,

Francisco.

Answers (0)