Java methods to send e-mails with HiperLinks

My Java application uses Java Domino methods to send e-mails. Is it possible to generate e-mails with hyperlinks, for example, “Click here” which opens a new browser window to http://www.ibm.com using Java?

Thanks.

Subject: Use the MIMEEntity and related classes

Here’s a simple Java agent based on your requirement that will send such an email to yourself.

import lotus.domino.*;

import javax.swing.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {



  try {

      Session session = getSession();

      AgentContext agentContext = session.getAgentContext();

  	Database db = agentContext.getCurrentDatabase();

  	Document doc = db.createDocument();

      String sendTo = session.getCommonUserName();

                

  	Stream stream = session.createStream();

  

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

  

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

  	doc.replaceItemValue("SendTo", sendTo);

  

  	MIMEEntity body = doc.createMIMEEntity();

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

  	header.setHeaderVal("Sample MIME email");

  	

  	stream.writeText("<a href='http://www.ibm.com'>Click here to go to the IBM website</a>");

  	body.setContentFromText(stream, "text/html", MIMEEntity.ENC_QUOTED_PRINTABLE);

  	stream.close();

  	doc.send(false);

  

  	session.setConvertMIME(true);	// Restore conversion

  	

      JOptionPane.showMessageDialog(null, "Email sent to " + sendTo);



  } catch(Exception e) {

      e.printStackTrace();

   }

}

}

Subject: lotus.notes.Document cannot be cast to lotus.domino.Document

Hi Wayne,

I have to modify your sample Java program since my program is not an agent.

I tried different ways to define Database db but failed with error message below at line "

Document doc = db.createDocument();":

lotus.notes.Document cannot be cast to lotus.domino.Document

Here is my test program.

private void sendHTMLMail()

throws lotus.notes.NotesException, NotesException {

lotus.domino.Session s = NotesFactory.createSession();

//… missing lines to define Database db

Document doc = db.createDocument();

Stream stream = s.createStream();

s.setConvertMIME(false);

doc.replaceItemValue(“From","abc@xyz.com”);

doc.replaceItemValue(“Subject”,“MIME testing e-mail”);

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

doc.replaceItemValue(“SendTo","abc@xyz.com”);

MIMEEntity body = doc.createMIMEEntity();

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

header.setHeaderVal(“Sample MIME email”);

stream.writeText(“Click here to go to the IBM website”);

body.setContentFromText(stream, “text/html”, MIMEEntity.ENC_QUOTED_PRINTABLE);

stream.close();

doc.send(false);

s.setConvertMIME(true); // Restore conversion

}

Any clues for this?

Your help is very much appreciated.

Alexis