Java Agent hangs sending attachment mails

I have a java agent that sends mails with attachment in a loop. But it hangs when second mail sending. I think it is a bug. Is there anyone faced this problem?

The code is here:

import java.io.File;

import lotus.domino.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {



  try {

    Session session = getSession();

     AgentContext agentContext = session.getAgentContext();

  	System.out.println("Sendmail started  ######");

	for(int i = 0 ; i < 5 ;i++){

	Document memo = agentContext.getCurrentDatabase().createDocument();

	System.out.println("#1");

	RichTextItem body = memo.createRichTextItem("Body");

	System.out.println("#2");

	body.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, "c:\\Temp\\Teklif"+i+".pdf", "Teklif");

	System.out.println("#3");

	memo.send("Mehmet Sunkur");  //!!!!! Hangs here when execution(i=1) comes second time

	System.out.println("#4");

	memo.removePermanently(true);

	System.out.println("#5");

	body.recycle();

	System.out.println("#6");

	memo.recycle();

	System.out.println("#7");

	System.gc();

	System.out.println("#8");

	File f = new File("c:\\Temp\\Teklif"+i+".pdf");

	System.out.println("#9");

	f.delete();

	System.out.println("#10");

	System.gc();

	System.out.println("Sendmail ended  #################");

	}



  } catch(Exception e) {

      e.printStackTrace();

   }

}

}

Subject: Check Agent Properties

I was having the same problem but the mail send method was not including an attachment. In the agent properties, the Target was set to “All Documents in the database”. To fix the problem I changed it to “None” since there was a search method in the code that searched through all the documents. Once I changed the target, it ran successfully.

Subject: check the error message.

I assume you are running the agent locally. Try to run the agent on server, and check the log.nsf to see what is the run-time error.

Subject: Are you saving the document?

Your using “removePermanently” but you are not saving the document? So your removing something that isn’t there. Can try setting “setSaveMessageOnSend” to true prior to the send command.