Java agent, creating MIME type mail

Hi, I have an agent that sends emails to selected users, what I would like to do is to change email format to be MIME type. Here is the code, does anybody can see what is wrong there. Text still is shown as text without formating(I just testing here the output).

Thanx

try {

	  Session session = getSession();

AgentContext agentContext = session.getAgentContext();

Stream stream = session.createStream();

session.setConvertMIME(false); // Do not convert MIME to RT

Database db = agentContext.getCurrentDatabase();

Document doc = db.createDocument();	

doc.replaceItemValue("Form", "Memo");

MIMEEntity body = doc.createMIMEEntity();

MIMEHeader header = body.createHeader("Subject");

header.setHeaderVal("MIME message");

header = body.createHeader("To");

header.setHeaderVal("Robert Ficek");

stream.writeText("<html><head><title>Sample HTML email via MIME</title></head></html");

  	body.setContentFromText(stream, "text/plain;charset=UTF-8",

   	 MIMEEntity.ENC_NONE);

stream.close();

doc.send(false);

} catch(Exception e) {

  e.printStackTrace();

}

The output that I get is

Sample HTML email via MIME

Subject: java agent/mime email - working example

I know it’s an old post, but in case anyone else is looking for a quick java MIME email example, see below. All I changed in Robert’s code was the body.setContentFromText (changed content-type to text/html) and stream.writeText (added content in the body, since the head content doesn’t display):

try {

Session session = getSession();

AgentContext agentContext = session.getAgentContext();

Stream stream = session.createStream();

session.setConvertMIME(false); // Do not convert MIME to RT

Database db = agentContext.getCurrentDatabase();

Document doc = db.createDocument();

doc.replaceItemValue(“Form”, “Memo”);

MIMEEntity body = doc.createMIMEEntity();

MIMEHeader header = body.createHeader(“Subject”);

header.setHeaderVal(“MIME message”);

header = body.createHeader(“To”);

header.setHeaderVal(“Robert Ficek”);

stream.writeText(“Sample HTML email via MIMEHere is a test”);

body.setContentFromText(stream, “text/html;charset=UTF-8”,

MIMEEntity.ENC_NONE);

stream.close();

doc.send(false);

} catch(Exception e) {

e.printStackTrace();

}