Michael T
Michael T

Reputation: 1955

What are all the fields available in a Notes email document in VBA

I have written VBA code to send an email from a group mailbox. I set the principal field to say where the mail comes from. It almost works correctly, putting the message in the sent items of the group mailbox. Even though I have the group mailbox name in the Principal field, it still says it was sent my me. I discovered that whichever user looks at the message in sent items, it says it was sent by that user (it is a dynamic field). I want to set that From field, and I discovered I can do that with something like '.from = "(User Name)"'.

So I am aware of the basic variables available, such as .SendTo, .CopyTo, .Principal, .From. But I have done web searches and I can't figure out how to get a comprehensive list of all the variables available. Hopefully someone can point me to some documentation that lists these?

For reference here is my code:

Function EmailFromNotes(strSendTo As String, strCopy As String, strSubject As String, _
    strText1 As String, strText2 As String, strText3 As String, _
    strText4 As String, strText5 As String, strAttachment As String, strFrom as String)

Dim notesdb As Object
Dim notesdoc As Object
Dim notesrtf As Object
Dim notessession As Object
Dim i As Integer

Dim AttachME As Object 'The attachment richtextfile object
Dim EmbedObj As Object 'The embedded object (Attachment)


    Set notessession = CreateObject("Notes.Notessession")

 ''''''''Group Mailbox'''''''''''''''''''''''''''''''''''''''''''''''''
    Set notesdb = notessession.GetDatabase("Servername", "mailin\GroupMailbox.nsf")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    'Open the mail database in notes
    If notesdb.IsOpen = True Then
    'Already open for mail
    Else
    notesdb.OPENMAIL
    End If

    Set notesdoc = notesdb.CreateDocument
    Call notesdoc.ReplaceItemValue("Subject", strSubject)
    Set notesrtf = notesdoc.CreateRichTextItem("body")
    Call notesrtf.AppendText(strText1 & vbCrLf & strText2 & vbCrLf & strText3 & vbCrLf & strText4 & vbCrLf & strText5)
    '''strCopy = "[email protected]"
    notesdoc.SendTo = strSendTo
    notesdoc.CopyTo = strCopy
    notesdoc.from = strFrom

''''''''Group Mailbox'''''''''''''''''''''''''''''''''''''''''''''''''
    notesdoc.principal = "Group Mailbox Name"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

If strAttachment = "" Then
Else
    Set AttachME = notesdoc.CreateRichTextItem(strAttachment)
    Set EmbedObj = AttachME.EmbedObject(1454, "", strAttachment)
End If

    Call notesdoc.Save(True, False)
    notesdoc.SaveMessageOnSend = True
    Call notesdoc.Send(False, strSendTo)
    Set notessession = Nothing

End Function

Upvotes: 0

Views: 3114

Answers (3)

In the RFC 5322 Standard the field From has a different purpose than in Lotus Notes, because it is always identifying the owner of the mail.box. Instead of using the field Principal to identify the owner of the mail.box in which an email was written, the field Sender is used to identify the effective user who produced the email. The field Principal is not (or better said no longer) accepted in the email header by many email providers and bounced back referring to being not RFC 5322 compliant. In messages produced by LotusScript directly in a document saved in the mail.box, you should use the field From instead of the field Principal and add the field Sender for the email address of the effective sender (sent by), who in a regular Lotus Email would be in the field From. If you prefer to have all replies to the effective sender instead of the person identified in the field From (original LN field Principal), you need to add the field ReplyTo with the same address as in der field Sender.

Upvotes: 0

Michael
Michael

Reputation: 1

Mail fields are defined by an RFC for all mails in general. http://en.wikipedia.org/wiki/Email#Message_header RFC 5322 https://www.rfc-editor.org/rfc/rfc5322

Upvotes: 0

Richard Schwartz
Richard Schwartz

Reputation: 14628

Unlike many other mail systems, Lotus Notes is finicky about spoofing the From field. The NotesDocument.Send() method doesn't want you to do it, and will override what you put in there. The Principal field is provided so you can say who you are sending on behalf of, but the From is supposed to be the true name of the actual sender. If you look at the document properties for the message in your Sent folder, I believe you'll find that the From field does indeed contain your name, not the name that your code is trying to put in that field!

There is a way around this, at least for the Sent message. Instead of relying on the SaveMesasageOnSend property, you can just use NotesDocument.Save() to write the document directly to the group mailbox, making sure that you set the PostedDate and not the DeliveredDate so that it will appear in the Sent view. It will be missing other fields that the Domino router would normally have added for you, though, like the MessageID and a few others -- but that might not be important for you. The message should still be viewable. In any case, as complex as it is, the formulas in the fields on the Memo form and its associated subforms in the mail template are your ultimate guide for figuring out how what the user sees is related to the actual values that are stored in the document.

If you're also concerned about making sure that recipients don't see your name, there's another trick. It involves directly writing the message to the router mailbox (the mail.box file). I've seen some systems, however, where there's code in place to prevent spoofing even if you do this, so it's something you'll have to try and see if it will work.

BTW: Are you asking about what the users see when they look at the index of the Sent view? That should be showing the value in the Principal field. Or are you asking about what the users see when go the Sent view and open the message? That should display the Principal field, followed by a newline and then "Sent by:" the From field. (Bear in mind that the From field is not likely the value that your code set due to the anti-spoofing provisions that I described.) Does this match what you are seeing?

Upvotes: 3

Related Questions