Smalltalk mail classes
Here is a step-by-step example showing how to send a mail document using the Smalltalk classes provided with VA Smalltalk Domino Connection. For this example it is assumed that you have a Notes client workstation set up to server-based mail (which is the common setting for a LAN based installation).
As stated before, the mail system is based on standard Domino databases. You will not need to learn any new classes or techniques to send mail.
Sending mail
To send mail and store a mail document in your mail database, you need to have access to two databases: mail.box and yourmail.nsf (where yourmail is presumed to be the name of your mail file). For a LAN based setup you will find both databases on your Domino mail server.
Note:
You must at least have depositor access to the mail box database to pass a document to the mail router.
You will create a new document in your mail file using the simple newNoteFromComputedForm: method implemented in AbtLnDatabase and then you will fill in the necessary information to send a mail. The document will be stored in the mail box. The mail router will take care to deliver the mail.
| mailServerConnection mailFileName mailFile mailBox
localMemo mailMemo locator |
"Startup runtime system"
AbtLnEnvironment startUp.
"Create a connection to your mail server"
mailServerConnection := AbtLnConnection mailServer.
"Initialize a locator on your mail server"
locator := AbtLnNameLocator new domain: mailServerConnection server.
"Set up the locator to find out about mail file names"
locator addNameSpace: (AbtLnNameSpaceUser new mailFile).
"Set your user name to be checked by the locator"
locator find: AbtLnEnvironment currentUserName.
"Get your mail file name from the locator result. As you have only one mail file,
using 'first' is convenient and will work"
mailFileName := locator lookup first at: 'MAILFILE' ifAbsent: [nil].
"Open your personal mail file"
mailFileName notNil
ifTrue:
mailFile := mailServerConnection openDatabase: mailFileName.].
"Open the mail server's mail box file"
mailBox := mailServerConnection openDatabase: 'mail.box'.
"Create a new document based on the 'Memo' form. Use the default value
formulas, and inherit field definitions"
localMemo := mailFile newNoteFromComputedForm: 'Memo'.
"Create a new document on the mail box on the server"
mailMemo := mailBox newNote.
"Set field values for the memo"
"Set recipients"
localMemo addTextListNamed: 'Recipients'.
localMemo at: 'Recipients' put: AbtLnEnvironment currentUserName.
"Set sendTo field - to be displayed in mail views and forms"
localMemo at: 'SendTo' put: AbtLnEnvironment currentUserName.
"Set a subject"
localMemo at: 'Subject' put: 'Test mail from Smalltalk to Domino'.
"Set contents of the mail body"
localMemo at: 'Body' put: 'This text is the mail body converted from ASCII to RTF
format.'.
"Copy the contents of the local memo to the memo created in the remote mail box"
"Do not use the itemDic: method in another context"
mailMemo itemDic: localMemo itemDic.
"Store the document in the mail box. This will pass it to the mail router"
mailMemo store.
"Close both databases"
mailFile close.
mailBox close.
"Shutdown runtime system"
AbtLnEnvironment shutDown.
The code above is a very simple approach to sending mail, and it will not satisfy all requirements that are imposed by recent mail database templates. Since the introduction of the Drafts, the Sent and the Inbox views in the mail template, you need to supply additional fields to make the mail documents show up in the appropriate folders. What follows is a short description of what is needed to implement mail that works in conjunction with a mail database of Domino or Notes Version 4.5 or later (changes that applied to templates in later Domino versions may require additional effort).
The Sent view
A mail document that is displayed in the Sent view must be stored in the users mail file and contain a field named PostedDate. The field should contain the actual date when the document was copied to the mail box file. Also the field named DeliveredDate must be absent or empty.
The Drafts view
A mail document is displayed in the Drafts view under the following conditions: The field named PostedDate is empty or not present, the field named $MessageType is empty or not present and the field named ExcludeFromView contains other values than the string "D".
SendTo, CopyTo and BlindCopyTo
Usually the Memo form displays values for To, cc and bcc (SendTo, CopyTo and BlindCopyTo). You have to supply the values for theses fields.
The following code sample shows you how to create a mail document that will comply with these requirements:
| mailServerConnection localMemo mailFile mailBox
mailMemo theRecipient theCopyRecipient theBlindCopyRecipient |
"Start runtime system"
AbtLnEnvironment startUp.
"name the recipients"
"change the names according to your requirements"
theRecipient := 'Rachel Hunter'.
theCopyRecipient := 'Hendrik Hoefer'.
theBlindCopyRecipient := 'Morgan Shrap'.
"Create a connection to the default mail server"
mailServerConnection := AbtLnConnection mailServer.
"open the router mail box file"
mailBox := mailServerConnection openDatabase: 'mail.box'.
"open the mail file of the sender - that is the person who executes this
code"
"change that to your mail file if you want to execute the code"
mailFile := mailServerConnection openDatabase: 'mail\tester.nsf'.
"create a new mail document in the mail box"
mailMemo := mailBox newNote.
"Add sender information"
mailMemo addTextNamed: 'FROM'.
mailMemo at: 'FROM' put: AbtLnEnvironment currentUserName.
"Create and set the sendTo field"
mailMemo addTextListNamed: 'SENDTO'.
mailMemo at: 'SENDTO' put: (OrderedCollection with: theRecipient ).
"Create and set the copyTo recipient"
mailMemo addTextListNamed: 'COPYTO'.
mailMemo at: 'COPYTO' put: (OrderedCollection with: theCopyRecipient ).
"Create and set the blindCopyTo recipient"
mailMemo addTextListNamed: 'BLINDCOPYTO'.
mailMemo at: 'BLINDCOPYTO' put: (OrderedCollection with:
theBlindCopyRecipient ).
"Take care the mail router gets to know every intended recipient"
mailMemo addTextListNamed: 'Recipients'.
mailMemo at: 'Recipients' put:
(OrderedCollection with: theRecipient
with: theCopyRecipient
with: theBlindCopyRecipient ).
"Set the subject of the mail"
mailMemo addTextNamed: 'SUBJECT'.
mailMemo at: 'SUBJECT' put: 'Here We Go...Again'.
"Set the mail body"
mailMemo addTextNamed: 'BODY'.
mailMemo at: 'BODY' put: 'Here we go '.
"take care of the *draft* folder"
mailMemo addTextNamed: 'ExcludeFromView'.
mailMemo at: 'ExcludeFromView' put: 'D'.
"Store the note in the router mailbox"
mailMemo store.
"Take care of the *sent* folder, copy the note to the users mail file"
localMemo := mailFile newNote.
localMemo itemDic: mailMemo itemDic.
"Fix the PostedDate field"
localMemo addTimeDateNamed: 'PostedDate'.
localMemo at: 'PostedDate' put: (Array with: Date today printString with: Time now printString).
"Store the document in the local mail file"
localMemo store.
"Shutdown runtime system"
AbtLnEnvironment shutDown.