0

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 = "michael.thain@pnc.com"
    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
Erik A
  • 31,639
  • 12
  • 42
  • 67
Michael T
  • 1,745
  • 5
  • 30
  • 42
  • 1
    I think your question needs some re-wording. You don't need to know, and there is no answer for "all the fields in a Notes document". Notes documents aren't just mail messages. If there were a list of all the items used in Notes mail messages, that might help you; but I'm not certain if there is a definitive list. I think your real question is: how I get my code to generate a Notes mail message in a group mailbox so that it will show the group mailbox name as the sender instead of my own name? – Richard Schwartz Jun 10 '13 at 18:56
  • No what I really want is a list of all the fields. For example, I am aware of these: .SendTo, .CopyTo, .From, .Principal. But I only know about these from other people's example code. What I want is a comprehensive list of all the fields possible and a brief description. Every other type of software I've accessed via VBA, I have been able to find a copybook online of all the fields. For Notes I have not been able to fine this. – Michael T Jun 15 '13 at 18:52
  • Notes is more than email. If you want a list of the basic fields in a Notes email message, that can probably be found. I'll dig around a little. If you want a comprehensive list of all the fields used in all versions of the Notes mail template in the past 25 years, that likely cannot be found. But a comprehensive list of all fields in a Notes document is impossible, because that would include every field used by every developer in every custom form in every custom application written using Notes. Your context is clear that you're asking about email, but my point is that your question is not. – Richard Schwartz Jun 15 '13 at 20:11
  • I don't want a list of fields in every developer's custom applications. I just want the list of fields available to me as a VBA developer interfacing with Notes. People somehow know to use .From, .Principal, .SendTo etc, but it seems there is no list of these, they just know it from other developers telling them. I found these examples in sample code in forums. It seems IBM has not provided a basic copybook of fields anywhere online. – Michael T Jul 12 '13 at 21:12
  • 1
    I've edited your question title to make it more explicit that you are only interested in 'Notes email documents'. I think you're right that IBM has never posted an explicit list of all the item names, but the Notes mail template and the Notes C API headers have been fully open source for more than 20 years, and (almost) all the fields you could be interested in can be found in one or the other. In both of these cases, though, it's a fishing expedition and you will need a fair amount of knowledge to know what to look for. I agree it would be good if there were a document. – Richard Schwartz Jul 13 '13 at 03:23

3 Answers3

3

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?

Richard Schwartz
  • 14,463
  • 2
  • 23
  • 41
  • I think I wasn't completely clear. I figured out that I can spoof the field using .From instead of .Principal. But I had to figure that out by trial and error. And to prevent having to randomly try words like that, I wanted a list of all the fields available. I'm gathering that such a list doesn't exist for Notes mail, and I will have to just figure it out through randomly looking at sample code. Most other softwares have some kind of documentation to tell you what all the possible fields are. – Michael T Jun 15 '13 at 18:57
0

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

Community
  • 1
  • 1
  • I'm not sure that this tells me the vba variables to access the various fields. This is just a primer on email protocols in general. I'm not sure I can find my answer in there. – Michael T Feb 19 '14 at 00:34
0

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.