Subject: Different approach, now seems to work
This time I used an XLST Transformation to render HTML direcly from a notes document. The result string transformed without problems. Here is the code:
Function NotifyXMLReceipient(doc As NotesDocument)
'Notifies the receipient of the document
'Uses an XLST Traansformation to generate the message body
Dim db As NotesDatabase
'Dim mdb As NotesDatabase
Dim v As NotesView
Dim confDoc As NotesDocument
Dim mailDoc As NotesDocument
Dim FieldList List As String
Dim body As NotesMIMEEntity
Dim header As NotesMIMEHeader
Dim stream As NotesStream
Dim s As New NotesSession
s.ConvertMime = False
NotifyXMLReceipient = False 'We asume we will fail
On Error Goto Err_NotifyXMLReceipient
Set db = s.CurrentDatabase
'Now compose the email message fields
Set mailDoc = db.CreateDocument()
mailDoc.Form = "Memo"
mailDoc.From = doc.From
'Subject can have fields too!
mailDoc.Subject = doc.Subject
mailDoc.SendTo = doc.SendTo
'Now compose the email body using an XLST Transformation
Set body = mailDoc.CreateMIMEEntity
Set header = body.CreateHeader("Content-Type")
Call header.SetHeaderVal("text/html")
Set stream = s.CreateStream
Call stream.WriteText(RenderWithXLST(doc,"NewEmailNotification"))
stream.Position = 0
Call body.SetContentFromText(stream,"text/html", ENC_NONE)
Call mailDoc.CloseMIMEEntities(True)
Call mailDoc.Send(False)
s.ConvertMime = True
NotifyXMLReceipient = True 'If we got here it worked
Exit_NotifyXMLReceipient:
Exit Function
Err_NotifyXMLReceipient:
NotifyXMLReceipient = False
Print "An error has occured in NotifyXMLReceipient: "
Print Err
Print ", "
Print Erl
Print ", "
Print Error$
Resume Exit_NotifyXMLReceipient
End Function
Function RenderWithXLST(doc As NotesDocument, styleName As String) As String
'Renders a Notes Document with a given XLST Stylesheet
'The stylesheet is retrieved from a global StyleSheetList
Dim xTrans As NotesXSLTransformer
Dim dxlSource As NotesDXLExporter
Dim xResult As NotesStream
On Error Goto Err_RenderWithXLST
Dim s As New NotesSession
'Check if we go a style and reinitialize the list
If Not Iselement(StyleSheetList(styleName)) Then
'We re-initialize the StyleSheetList
Call InitializeStyleSheetList
End If
'Second try
If Not Iselement(StyleSheetList(styleName)) Then
'The element is NOT available
RenderWithXLST = "Stylesheet "+styleName+" not found!"
Goto Exit_RenderWithXLST
End If
'Now the transformation!
'Reset the Style Position
StyleSheetList(styleName).Position = 0
'Now get the DXL... and transform
Set xTrans = s.CreateXSLTransformer
Call xTrans.SetStylesheet(StyleSheetList(styleName))
Set xResult = s.CreateStream
Call xTrans.SetOutput(xResult)
Set dxlSource = s.CreateDXLExporter(doc,xTrans)
'Only the process needs to be called, the transform is implicit
Call dxlSource.process
'Our stylesheet produces html
RenderWithXLST = xResult.ReadText
Exit_RenderWithXLST:
Exit Function
Err_RenderWithXLST:
RenderWithXLST = "Error in RenderWithXLST:"+Error$
Resume Exit_RenderWithXLST
End Function
And here the stylesheet (the dxl namespace in the xpath is the headache)
<?xml version="1.0" encoding="UTF-8"?>
<?xmlspysamplexml MailWithRichText.xml?>
<xsl:stylesheet version=ā1.0ā xmlns:xsl=āXSLT Namespaceā xmlns:dxl=āhttp://www.lotus.com/dxlā>
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>Reliable email - new message</title>
<style type="text/css"><![CDATA[
table { width : 100%; background-color : #fff; }
body { background-color : #CCCCCC; }
td { border : 1px dotted #CCCCCC; }
]]>
</head>
<body>
<xsl:apply-templates select="dxl:document"/>
</body>
</html>
</xsl:template>
<xsl:template match="dxl:document">
<!-- Here goes the content1 -->
Dear <xsl:value-of select="/dxl:document/dxl:item[@name='SendTo']/dxl:textlist/dxl:text"/>,<br/>
<br/>
There is a new realiable email message from <xsl:value-of select="dxl:item[@name='From']/dxl:textlist/dxl:text"/> waiting for you to be picked up. Please click on the link below to retrieve the message.<br/>
<xsl:value-of select="/dxl:document/dxl:item[@name='FetchHere']/dxl:textlist/dxl:text"/>
<br/>
<br/>
Your MailTracker Team.
<br/>
The information in summary:
<table class="mailmessage">
<thead>
<tr>
<th colspan="2">A new reliable Message</th>
</tr>
</thead>
<tbody>
<!-- Fields I want to show -->
<xsl:apply-templates select="dxl:item[@name='From']"/>
<xsl:apply-templates select="dxl:item[@name='SendTo']"/>
<xsl:apply-templates select="dxl:item[@name='ReplyUntil']"/>
<xsl:apply-templates select="dxl:item[@name='Subject']"/>
<tr>
<td align="center" colspan="2">
<a title="Retrieve your message online" target="_blank">
<xsl:attribute name="href"><xsl:value-of select="/dxl:document/dxl:item[@name='FetchHere']/dxl:textlist/dxl:text"/></xsl:attribute>
Retrieve your message online</a>
</td>
</tr>
</tbody>
</table>
<!-- the message as iframe -->
<iframe scrolling="auto" width="100%" height="300" id="themessage">
<xsl:attribute name="src"><xsl:value-of select="dxl:item[@name='FetchHere']/dxl:textlist/dxl:text"/></xsl:attribute>
</iframe>
</xsl:template>
<xsl:template match="dxl:item">
<tr>
<td>
<xsl:value-of select="@name"/>
</td>
<td>
<xsl:value-of select="./dxl:text"/>
<xsl:value-of select="./dxl:textlist/dxl:text"/>
<xsl:value-of select="./dxl:datetime"/>
</td>
</tr>
</xsl:template>
<!-- make sure nothing drops trhough -->
<xsl:template match="*"/>
</xsl:stylesheet>