Domino Connection : Samples for Domino and Notes Version 4.5 : Using mail : Using a form part to create and edit mail documents
Using a form part to create and edit mail documents
The AbtNotesDemoMail45 samples is part one of a two step example that shows you how to create a fully functional mail front-end. The second part of the mail application is the sample named Using a view part to list mails in a mail database. In general it is simple to create a document that is routed by the Domino mail system: you just have to add an item named recipients containing the intended recipients for that document as a text list and save the document in the mailbox file. (If you are not permanently connected to the network, the mail box file may be on your local system. Otherwise, the mail box file will be on your mail server). Your personal mail database uses more complicated concepts, because it offers additional features like: views that show the documents you sent, other views containing only documents you received and a view for drafts, not to speak of the calendar functions. When you use the simple mail approach described earlier, your documents will not be found in all the views of your mail DB. The following sample adds the required fields and functions to the standard mail part to make your mail/memo documents compatible with the Domino mail template (V.4.5/4.6). The mail form developed here will allow you to perform the following functions: create and send a mail memo from a sample mail database, send the document without storing it, send and store the document, and/ or save the document as draft without sending it. (You should check the different states of the memo using your Notes client). The form also provides means to select recipients from the name & address book as well as a separate dialog to configure the delivery options of the memo. Note that the most of the application can be created using the visual programming paradigm.
Step by Step description how to build the sample
Make sure you have performed the initial steps to rebuild the samples before you proceed (Preparation for Version 4.5 Samples).
1. Create a new visual part. Add a Domino Mail part from the parts palette to the free form surface. If you have not already done so, create a connection specification named MySampleMail for the local \vasample\va45mail.nsf database. If you have not already done so, create a connection specification named MyMailBox for the local \vasample\mailbox.nsf database. Double click on the mail part to configure it using the settings pages. On the first setting page select the MySampleMail alias to connect the mail part to the sample mail database. From the Available Forms drop down list box select Memo. Click on the Mail Settings notebook page to open the second settings page. In the Mail Box Settings section select MyMailBox.
2. This setting lets you store all documents that would be sent in an productive system to local database that represents a mail box. You can open this database (it comes with the sample databases and is named mailbox.nsf) and view the contents. That mail box will however not deliver your mail, because the mail router is not aware of this database. If you want your sample mail to really be delivered, create a connection specification for your mail server's mail box and set up your mail part using this connection spec.
3. Add the following items to the Field names that specify valid recipients list: SendTo, CopyTo, BlindCopyTo. The content of all of these field will be copied to the recipients field automatically prior to delivery. Click on the User Defined Items tag of the third notebook page and add the following extra items to the memo form: Returnreceipt (data type: Text), Deliveryreport (data type: Text), Deliverypriority (data type: Text), Importance (data type: Text), Postdate (data type: Time and Date). Apply the changes.
4. Connect the aboutToOpenWidget event of the main window to the open action of the mail part. Connect the aboutToCloseWidget event of the main window to the close action of the mail part. Also connect the openedWidget event of the main window to the newNote action of the mail part. You will always have a new document available when you open the application. Tear off the currentNote attribute of the mail part and drop it to the free from surface. Add entry fields for the following items: From (Text), SendTo (Text), CopyTo (Text), BlindCopyTo (Text), Subject (Text), Body (Multi Line Edit). Open the settings for each entry field and select the appropriate converters (text list for SendTo, CopyTo, BlindCopyTo, then text for From and Subject, and finally Composite for the Body). Connect the object attribute of each of the entry fields to the corresponding attribute of the currentNote part.
5. Add three buttons to the main window labeled: Send, Send and Save, Save as Draft. After that, connect the clicked event of the Save as Draft button to the storeNote action of the mail part. That action will store the new document in the mail database without copying it to the mail box. Add another connection: Select the clicked event of the Save as Draft button to the newNote action of the mail part, so a new mail is created after you decided to store the previous document. It is important to have the current date and time available for mail processing, because usually the mail documents based on a Domino 4.5/4.6 mail template contain an item named Postdate.
6. You have already added the appropriate item during setup of the mail part. Now you have to write a script to get the current time and date from the system. To do that, switch to the Public Interface Editor and add an attribute named currentTime. Select Add with Defaults, but delete the Set Selector because the current time is read only. Use the File menu option Generate default scripts, and select Generate all. Switch to the Script editor and write the following code to the currentTime method:
7. currentTime
8. "Return the value of currentTime."
9. ^AbtLnEnvironment currentTimeDate contents
10. You are now ready to program the Send and Save and the Send buttons. Connect the clicked event of the Send and Save button to the Postdate attribute of the currentNote part. Provide the necessary parameter by connecting the currentTime attribute of the main windows with the value attribute of the connection between Send button and Postdate. Connect the clicked event of the button to the sendMail action of the mail part and connect the clicked event of the button to the storeNote action of the mail part. Also connect the newNote action of the mail part to create a new document whenever the preceding document was sent. Be aware that the order of the connections is important to the functionality of the sample application. If you change or reverse the order, the sample will not function properly.
11. Proceed with the Send button. Build all connection like with the Send and Save button, but leave out the storeNote action of the mail part. Finally you need to provide some sender information. The current user's name can be retrieved from a database part. Tear off the database attribute of the mail part and connect the currentUserName attribute from the tear off to the object attribute of the field that is also connected to the From attribute of the current note. The mail form is now functional, but we will add some more features:
12. Add a second window named Recipients to the free form surface. You will use this window select from the list of available recipients. Also add an Domino Address Book to the free form surface. Double click on the address book part and configure the following settings: Select ConTo45PersAdrBook as connection specification (this a sample database that comes with the Domino Connection product) and select the $VIMPeopleAndGroups view as a source for displaying the list of valid recipients. Select the second notebook page named Address Book and $1 as Name Column. This selection chooses the appropriate column from the view that contains names and group names. $1 might seem to be a strange name for a column, but it is the way Domino labels columns that display calculated values. Have a look at the address book database and check out which column you selected. To open address book part when it is needed, do the following: Add a push-button named Address to the main window. Connect the clicked event of the button to the openApplicationModalWidget action of the Recipients windows. Add a Button named Cancel to the Recipients window and connect the clicked event to the closeWidget action of the Recipients window. Also connect the opened event of the Recipients window with the open action of the address book part and finally connect the AboutToCloseWidget event of the Recipients window with the close action of the address book part.
13. To make sure the address book view is always up to date connect the OpenedWidget event of the Recipients window with the update action of the address book part. Add a simple list and three more buttons to the Recipients window. Label the buttons SendTo, CopyTo and BlindCopyTo. The buttons will be used to transfer selected recipients to the current mail document. Now connect the items attribute of the list with the names attributes of the address book part to display the list of available recipients in the list. To copy selected recipients for the Recipients windows list do the following: Connect the clicked event of the SendTo button with the object attribute of the SendTo entry field in the main window. You have to supply a parameter for the event-to-attribute connection: select the selectedItems attribute of the list in the Recipients window to the value attribute of the connection. Proceed with the other buttons and connect them to their respective entry fields.
14. As the last step, add another window to the free form surface called DeliveryOptions. This window will be used to set the delivery options for the current mail document. To open that window, add another button to the main windows and label it: DeliveryOptions. Connect the clicked event to the openApplicationModalWidget action of the DeliveryOptions window. Add four drop down listboxes to the DeliveryOptions window. Label them Return receipt, Delivery Report, Delivery Priority and Importance. You now have to supply the possible values of each of the delivery options. To do that, open the settings for each drop down list and supply the following values for the items attribute: List Name Values Return receipt ReturnReceipt, Delivery report Only on failure, Confirm delivery, Trace entire path Delivery priority High, Normal, Low Importance High, Normal, Low.
15. Now connect each of the lists selectedItem attributes to the appropriate item in the currentNote part. You have now built a part that works much like a Memo form in the Lotus Notes client. Continue with the next sample to create an appropriate view for the mail sample: If anything does not work as expected, compare your work with the sample code in AbtNotesDemoApp45
Last modified date: 01/29/2015