Attach file from Java Agent

Hi everybody,

Please, how can I send attachment from JavaAgent?

Anybody can give me an example code? PLEASE

Thanks and regards.

Tonny Cardenas

Subject: Attach file from Java Agent

From Designer help, verbatim:

This agent creates a rich text item and embeds an attachment.

import lotus.domino.*;
import java.util.Vector;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
Database db = agentContext.getCurrentDatabase();
Document doc = db.createDocument();
doc.replaceItemValue(“Subject”, “Attachment”);
RichTextItem body = doc.createRichTextItem(“Body”);
body.appendText(“Here is the attachment:”);
body.addNewLine(2);
body.embedObject(EmbeddedObject.EMBED_ATTACHMENT,

  null, "c:\\notes\\notes.ini", "notesini");
  // Save the document
  doc.save(true, true);
} catch(NotesException e) {
  System.out.println(e.id + " " + e.text);
  e.printStackTrace();
}

}
}

The above code looks to be written to run on Windows so you’ll need to make a few tweaks to it if you want it to run on your server, which I see runs on an iSeries. Most notably, you’d want to avoid using hardcoded backslashes when building a path to the target file . . . try using java.io.File.separator instead. For example:

StringBuffer asbuffPath = new StringBuffer(32);

asbuffPath.append(File.separator).append(“notes”);

asbuffPath.append(File.separator).append(“notes.ini”);

System.out.println("File path constructed = " + asbuffPath);

Output should be something like:

File path constructed = /notes/notes.ini

hth,

dgg

Subject: RE: Attach file from Java Agent

Dallas, thanks a lot for your help.

Best regards,

Tonny Cardenas