You are viewing this page out of context. To see it in the context it is intended please click here.
About This Page
Reply posted by Ronald Portier on Fri 4 Jan 2008 in response to HTML Emails The Easy Way
Java version
Great article, however I needed this logic within a web application (to useDomino as a mail-server from within an iSeries application).
As other people might be in the same situation I submit the translation to Java
of the lotusscript code.
The application makes a connection to the Domino server through DIIOP to get a
global notes Session parameter. Then this is used in the sendhtmlmail method.
If people need the full application, I can send the jar file through e-mail.
/**
* Connects to the Domino application server, and sends an email. *
*
* @param sendTo
* @param copyTo
* @param subject
* @param message
* @param htmlMessage
*/
public void sendHtmlMail(String sendTo, String copyTo, String subject,
String message,
String htmlMessage) {
lotus.domino.Document memo = null;
try {
this.m_dominoSession.setConvertMime(false); // MIME gebruiken i.p.v.
Rich Text
memo = m_dominoMailDb.createDocument();
memo.appendItemValue("Form", "Memo");
// memo.appendItemValue("Importance", "1");
memo.appendItemValue("CopyTo", copyTo);
memo.appendItemValue("Subject", subject);
// Nu gaan we een MIME entity aanmaken
lotus.domino.MIMEEntity body = memo.createMIMEEntity();
// MIME headers aanmaken
lotus.domino.MIMEHeader header = body.createHeader("MIME-Version");
header.setHeaderVal("1.0");
header = body.createHeader("Content-Type");
header.setHeaderValAndParams(
"multipart/alternative;boundary=\"=NextPart_=\"");
// Add plain text part
lotus.domino.MIMEEntity child = body.createChildEntity();
lotus.domino.Stream stream = this.m_dominoSession.createStream();
stream.writeText(message);
child.setContentFromText(stream, "text/plain", MIMEEntity.ENC_NONE);
stream.close();
// Add html part
child = body.createChildEntity();
stream = this.m_dominoSession.createStream();
stream.writeText("<html>", Stream.EOL_CR);
stream.writeText("<head>", Stream.EOL_CR);
stream.writeText("<style>body{font-family:verdana,arial,helvetica,sans-serif}a{c
olor:orange}</style>", Stream.EOL_CR);
stream.writeText("</head>", Stream.EOL_CR);
stream.writeText("<body>", Stream.EOL_CR);
stream.writeText(htmlMessage, Stream.EOL_CR);
stream.writeText("</body>", Stream.EOL_CR);
stream.writeText("</html>", Stream.EOL_CR);
child.setContentFromText(stream, "text/html;charset=\"iso-8859-1\"",
MIMEEntity.ENC_NONE);
stream.close();
// Send Message
memo.send(false, sendTo);
System.out.println("HTML bericht " + subject + " verzonden.");
} catch (NotesException e) {
System.out.println("Error - " + e.id + " " + e.text);
// e.printStackTrace( System.out );
} finally {
try {
if (! (memo == null )) {
memo.recycle();
memo = null;
}
this.m_dominoSession.setConvertMime(true); // restore default
} catch (NotesException fe) {}
}
}