To create an email message using the Notes APIs, you would code something like the following. This is working code which creates an editable email message by clicking on a button. This code will present a message box to the user asking for the text which they want to add to the message. The user has the option to cancel the email prior to sending.
Sub Click(Source As Button)
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim db As NotesDatabase
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument, doc2 As NotesDocument
Dim itemRT As NotesRichTextItem
Dim item As NotesItem
Dim strComments As String
Dim strBody As String
Dim strSubject As String
Dim varSubject As Variant
Dim strInputText As String
Const NEW_LINE = |
|
'This section is used to select who will receive responses, enter the number of people who will receive responses next to SendTo, and then below specify the people starting with (0) -----
'--------------------------------------------------------------------------------------
Dim SendTo(2) As String
SendTo(0) = "Notes ID of email recipient"
'--------------------------------------------------------------------------------------
'This section determines what the subject tag line will be for the feedback note. Enter what you would like next to SubjTemp
'--------------------------------------------------------------------------------------
Dim SubjTemp As String
SubjTemp = "Feedback -- "
'--------------------------------------------------------------------------------------
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
Set db = session.CurrentDatabase
Set itemRT=doc.getFirstItem("body") ' get rid of attachments from background document
If doc.HasEmbedded = True Then ' see if background document has any attachments
Forall x In itemRT.EmbeddedObjects
If x.type=1454 Then
x.remove
End If
End Forall
End If
Set doc2 = doc.CreateReplyMessage( False )
Set item = doc.GetFirstItem("Subject")
varSubject = item.Values
strSubject = SubjTemp & varSubject(0)
Set item = doc2.ReplaceItemValue("Subject", strSubject)
strInputText = "Thank you for providing us with your valuable feedback!" & NEW_LINE & "Please enter your comments in the space below." & NEW_LINE & "If you do not want to send a feedback, click on Cancel."
strComments = Inputbox$(strInputText, "Comments")
If strComments = "" Then
Msgbox "You did not enter any comments, a feedback message will not be sent."
Else
strBody = "Very Useful" & NEW_LINE & NEW_LINE & "Comments: " & strComments
Set item = doc2.ReplaceItemValue("Rating", "Very Useful")
Set item = doc2.ReplaceItemValue("Comments", strComments)
Call doc2.Removeitem("Body") ' get rid of original body field
Set item = doc2.ReplaceItemValue("Body", strBody)
doc2.SendTo = SendTo
Call doc2.Send(False)
Messagebox "Thank you for your feedback, a message has been sent.", MB_OK, "Message Sent"
End If
End Sub