function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
orikkerorikker 

Attach external file when use sendemail() call

Is there a way to attach a file from your computer when run java program using sendemail() api call?

 

book suggests the following code

EmailFileAttachment efa = new EmailFileAttachment();
    byte[] fileBody = new byte[1000000];
    efa.setBody(fileBody);
    efa.setFileName("attachment");

 

 

but where do I actually set the path to the file?

VirendraVirendra

You can  try: 

 

 

EmailFileAttachment efa = new EmailFileAttachment();
File file = new File("c://Test.java");
byte[] fileBody = new byte[(int) file.length()];
efa.setBody(fileBody);
efa.setFileName("attachment");

 

VirendraVirendra

Read previous code as :: 

 

 

EmailFileAttachment efa = new EmailFileAttachment();
File file = new File("c://Test.java");
byte[] fileBody = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(fileBody );
efa.setBody(fileBody);
efa.setFileName("attachment");