?
Solved

Lotus Notes Automation using Visual Basic

Posted on 2011-03-09
6
Medium Priority
?
2,588 Views
Last Modified: 2013-12-18
Using Visual Basic 2008 and Lotus Notes 8.5.

I use this code to automate the Lotus Notes UI to create an HTML format email with attachment.
sess = CreateObject("Notes.NotesSession")
ws = CreateObject("Notes.NotesUiWorkspace")
db = sess.GetDatabase("", "", False)

If Not db.IsOpen Then db.OpenMail()
doc = db.CreateDocument()
Call doc.ReplaceItemValue("Form", "Memo")

' add the body as a mime html part
convertMime = sess.convertMime
sess.convertMime = False
stream = sess.CreateStream()

stream.WriteText(strBody)
mimeBody = doc.GetMIMEEntity("Body")

If mimeBody Is Nothing Then
     mimeBody = doc.CreateMIMEEntity("Body")
End If

mimeHtml = mimeBody.CreateChildEntity()
Call mimeHtml.SetContentFromText(stream, "text/html; charset=""iso-8859-1""", ENC_QUOTED_PRINTABLE)
Call stream.Close()

'handle the attachment
If Attachment.Length > 0 Then
                mimeFile = mimeBody.CreateChildEntity()
                mimeHeader = mimeFile.CreateHeader("Content-Transfer-Encoding")
                Call mimeHeader.SetHeaderVal("binary")
                mimeHeader = mimeFile.CreateHeader("Content-Disposition")
                Call mimeHeader.SetHeaderVal("attachment; filename=" & "Order Acknowledgement.pdf")
                Call stream.Open(Attachment, "binary")
                Call mimeFile.SetContentFromBytes(stream, "text/plain", ENC_NONE)
                Call mimeFile.EncodeContent(ENC_IDENTITY_8BIT)
                Call stream.Close()
End If

Open in new window


When I continue the code with this:
            Call doc.Save(True, False)
            uidoc = ws.EditDocument(True, doc)
            Call uidoc.FieldSetText("EnterSendTo", [To])
            Call uidoc.FieldSetText("EnterCopyTo", [CC])
            Call uidoc.FieldSetText("Subject", Subject)

            ' bring the window to the front
            Call AppActivate(uidoc.WindowTitle)

Open in new window

the email is created with the attachment, but the signature block is missing.  I don't beileve the default lotus notes template is being used.

When I substitute the second block of code with this:
           'copy generated HTML to clipboard
            Call doc.Save(True, False)
            uidoc = ws.EditDocument(True, doc)

            Call doc.Remove(True)
            Call uidoc.GotoField("Body")
            Call uidoc.SelectAll()
            Call uidoc.Copy()
            uidoc.Document.SaveOptions = "0"
            uidoc.Document.MailOptions = "0"
            Call uidoc.Close()

            ' compose a new memo and paste the body
            uidoc = ws.ComposeDocument(db.Server, db.filePath, "Memo")
            Call uidoc.GotoField("Body")
            Call uidoc.Paste()

            Call uidoc.FieldSetText("EnterSendTo", [To])
            Call uidoc.FieldSetText("EnterCopyTo", [CC])
            Call uidoc.FieldSetText("Subject", Subject)

Open in new window

then the signature block is there, but the attachment is not copied (missing) from the email.  It seems that the default Lotus Notes template is being used.

I need help with the code so that a HTML format email with attachment is created that uses the default template and has the signature block inserted.  I think the "CreateDocument" and "ComposeDocument" commands use two different templates.

Thanks.


0
Comment
Question by:waverazor
  • 2
  • 2
  • 2
6 Comments
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 1500 total points
ID: 35093392
> I think the "CreateDocument" and "ComposeDocument" commands
> use two different templates.
Nope. ComposeDocument is an UI method, it uses a form in the template, whereas CreateDocument is a back-end method, which uses no template at all. Better not mix the use of those two!

Likewise, you shouldn't mix the use of other UI and non-UI methods and objects. If you want the user's signature to be added automatically, you'd better use the UI calls all the way. Which beans: don't use CreateDocument, but start with ComposeDocument and go from there. In this way, the signature will be added BEFORE you add text. But I suppose you can't create a MIME mail, the UI is not meant to create MIME mails.

If you try the other way round, meaning that you use CreateDocument, you refrain from using EditDocument but you set the fields SendTo, CopyTo and BlindCopyTo in your code, you'll have a problem adding the signature. You have to do that all by yourself, which means that you have to use code like this

Dim profdoc As Notesdocument
Set profdoc = maildb.GetProfileDocument("CalendarProfile")

to get the profile document that stores info about the signature. There are fields there that tell you where to get the signature and what type it is, how to insert it.

Maybe you can use code in the mail template to add the signature, but I don't know that code well enough to give you an answer to that.

I hope this helps you a little...
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 35094241
Well, CreateDocument is back-end and ComposeDocument is front-end, but I use front-end and back-end classes together all the time.  You just need to be aware of the differences, how they relate, and when to use each.  The reason that CreateDocument does not set the signature is because there are no hooks that allow the developer to extend the functionality.  When ComposeDocument is used, however, code in the Form's events are executed.  This is how you extend functionality of the ComposeDocument and EditDocument methods.  The Memo form probably uses the QueryOpen or PostOpen event to check whether the document is new - if it is, the signature is added.

The best solution is to create the document in the backend adding in the signature as specified by the CalendarProfile document (you could look at the Lotus code to see how they are doing this), then display it to the user using ws.EditDocument.

That's a lot of work, though.  As a workaround, I have done this in the past...
1) Create back-end document using mime or richtext.
2) Display it temporarily using ws.EditDocument. (it is open for only an instant.  most users won't notice)
3) Copy the body to the clipboard using uidoc.Copy.
4) Close the temp uidoc.
5) Compose new memo.
6) Paste in the body using uidoc.Paste.

Not the best solution because it destroys the contents of the clipboard, but it is the only way I have found to compose a mime or richtext memo with a signature.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 35094376
>  You just need to be aware of the differences...
With an emphasis on "just"... ;-) I mentioned "better not", for the reasons you mentioned and also the fact that rich-text fields aren't synchronised.

I almost agree with the last sentence, for it should be possible to include the Signature from the profile document using only the back-end class. Also a lot of work...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:waverazor
ID: 35096778
Sjef,

Using the code below got me the signature, but the new line characters where not recognized in the html email.  My signature appeared like this (on one line): Donald Duck Any Company 123 Main St (123) 456-7890.
 
Dim profdoc As Notesdocument
Set profdoc = maildb.GetProfileDocument("CalendarProfile").("Signature")(0)

I added this like of code and the signature is formated with line breaks:

stream.WriteText(sig.ToString.Replace(vbCrLf, "<br>"))

Bill,

You've help me very much in the past.  The code I use is yours.  I believe that I have already tried what you suggest in your workaround (the 3rd block of code in my 1st posting), but the attachment does not get copied to the new email.  When I use the 2nd block of code in the 1st posting (I get the attachment, but I lose the signature) the attachment is not in the body of the email, but in the heading portion to the left of the To, cc, bcc, and subject lines.  Maybe this location is why it is not copied to the new email?  If my 3rd block of code is not what you suggest, please provide a code sample.

Thanks.
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 35097050
I just tested, and you're right.  My workaround no longer works because 8.5 changes the way that MIME attachments are displayed.  Since they are no longer rendered in the body field, the copy-paste solution no longer works.

The only true solution I know of is to code the 'insert signature' part by hand.  I would start by looking at the UIMemoDocument.InsertSignature method in the mail file design.  It should have everything you need.
0
 

Author Closing Comment

by:waverazor
ID: 35112525
The solution should include: profdoc.GetItemValue("Signature")(0) to get the text signature.

However, this will not work for a HTML signature.  For a HTML signature I read the HTML file and appended the contents to the body.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question