Hi, I have created an agent that generates an HTML email using MIME and my intention is then to attach files (word, excel, txt etc) to this email. I have an egent that works fine when run from the client… it generates the HTML email and adds an attachment (harcoded filepath on my C:). When i try and run this from a webQuerysave on a web form it says the file has no content…? I would appreciate any help on this… the code is below… thanks in advance.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim parent As NotesMimeEntity
Dim child1 As NotesMimeEntity
Dim child2 As NotesMimeEntity
Dim header As NotesMimeHeader
Dim fileName As String
Dim stream As NotesStream
Dim prompt As String
Dim recipients As String
session.ConvertMime = False ' We do want Notes to convert MIME to Rich Text
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
Call doc.ReplaceItemValue("Form", "Memo")
Call doc.ReplaceItemValue("Subject", "Doc created " _
& Format$(Now, "dd mmm yyyy hh:nn:ss AM/PM"))
' Hard-code the path to your local Notes.ini file. This could be found out programmatically
' by looking at the Windows registry, but that is beyond the scope of this article.
fileName = "c:\temp\testcsv.txt"
' Create all the Entities - one parent, three children.
Set parent = doc.CreateMIMEEntity
Set child2 = parent.CreateChildEntity
Set child1 = parent.CreateChildEntity(child2) ' Create so that children 1 & 2 are siblings
' Add a couple of headers to child 2 (that will hold the attachment).
Set header = child2.CreateHeader("Content-Transfer-Encoding")
Call header.SetHeaderVal("binary")
Set header = child2.CreateHeader("Content-Disposition")
Call header.SetHeaderVal({attachment; filename="notes.ini"})
' Build the HTML message content. This HTML goes into child 1
Set stream = session.CreateStream
Call stream.WriteText({Here is my <font color="red">notes.ini</font>})
Call stream.WriteText({ file for your reference.<br><br>})
Call child1.SetContentFromText(stream, "text/html", ENC_NONE)
Call stream.Truncate
' Bring the attachment into its entity (child 2)
Set stream = session.CreateStream
If Not stream.Open(fileName, "binary") Then
Msgbox "Could not open " & fileName, 16, "Open failed"
Goto ExitSub
End If
If stream.Bytes = 0 Then
Msgbox "File " & fileName & " has no content", 16, "No Content"
Goto ExitSub
End If
Call child2.SetContentFromBytes(stream, "text/plain", ENC_NONE)
Call child2.EncodeContent(ENC_IDENTITY_8BIT)
Call stream.Close
' Prompt for the recipients
'prompt = "Enter the recipients for this memo. Separate multiple values with a comma"
recipients = "mandip.sodhi@nottscc.gov.uk"
If recipients = "" Then
Msgbox "You did not enter any recipients. Message not sent.", 16, "Not Sent"
Else
Call doc.Send(False, Split(recipients, ","))
End If
ExitSub:
session.ConvertMime = True ' Reset the value
End Sub