Solved

Creating Lotus Notes mail and displaying it using .NET

Posted on 2007-12-07
11
1,300 Views
Last Modified: 2013-12-18
Hi
I'm working on some .NET code to create a Lotus Notes mail. I got this working but after the mail is created I need to display the mail in Lotus Notes so that the user can edit it/adding recipients etc. before sending it.
The Code works fine but I do not want the code line :MailDoc.SEND(0)
I want something like MailDoc.Show

Please help !!
Peter



Public Sub SendNotesMailnew(ByVal Subject As String, ByVal Attachment As String, ByVal Recipient As String, ByVal BodyText As String)
 
        Dim NSession As lotus.NOTESSESSION = CType(CreateObjectFromProgID("Notes.NotesSession"), lotus.NOTESSESSION)
        Dim UserName As String 'The current users notes name
 
        Dim NMailDatabase As lotus.NOTESDATABASE '= CType(CreateObjectFromProgID("Notes.NOTESDATABASE"), lotus.NOTESDATABASE)
 
        UserName = NSession.USERNAME
        NMailDatabase = NSession.GETDATABASE("myserver", "mail\someperson.nsf", False) '"", "names.nsf", False)
 
        If NMailDatabase.ISOPEN = False Then
            NMailDatabase.OPENMAIL()
        End If
 
        Dim MailDoc As lotus.NOTESDOCUMENT 'The mail document itself
        MailDoc = NMailDatabase.CREATEDOCUMENT() 'Create the mail document
        MailDoc.REPLACEITEMVALUE("Form", "Memo")
        MailDoc.REPLACEITEMVALUE("SendTo", Recipient)
        MailDoc.REPLACEITEMVALUE("Subject", Subject)
        MailDoc.REPLACEITEMVALUE("PostedDate", Now)
 
        Dim test As Object = "False"
        Dim hallo As String = "True"
 
        Dim rt As lotus.NOTESRICHTEXTITEM
        rt = MailDoc.CREATERICHTEXTITEM("Body")
        rt.APPENDTEXT(BodyText)
 
        MailDoc.SEND(0)
 
    End Sub
 
    Public Function CreateObjectFromProgID(ByVal progID As String) As Object
        Dim comObjectType As Type = Type.GetTypeFromProgID(progID, True)
        Return Activator.CreateInstance(comObjectType)
    End Function

Open in new window

0
Comment
Question by:Contestoas
  • 6
  • 5
11 Comments
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 20428054
Here's how I do things in .Net.

If I'm only working in the back-end, I use the "Lotus Domino Objects" (Domino.NotesSession) so that my objects are early-bound.

If I need to use the Notes UI Classes, I don't include any Notes references, and use only Object variables for the Lotus classes (Notes.NotesSession).  I've never had much success using lotus.NOTESSESSION.

Anyway, here's the code.  The only thing that might give you trouble is adding the file attachment from the UI.
    Public Sub ComposeNotesMemo(ByVal Subject As String, ByVal Attachment As String, ByVal Recipient As String, ByVal BodyText As String)
 
        Dim sess As Object
        Dim ws As Object
        Dim uidoc As Object
        Dim mailServer As String
        Dim mailFile As String
 
        sess = CreateObject("Lotus.NotesSession")
        Call sess.Initialize()
        mailServer = sess.GetEnvironmentString("MailServer", True)
        mailFile = sess.GetEnvironmentString("MailFile", True)
        ws = CreateObject("Notes.NotesUiWorkspace")
        uidoc = ws.ComposeDocument(mailServer, mailFile, "Memo")
        uidoc.FieldSetText("EnterSendTo", Recipient)
        uidoc.FieldSetText("Subject", Subject)
        uidoc.GotoField("Body")
        uidoc.InsertText(BodyText)
        AppActivate("New Memo - Lotus Notes")
        uidoc = Nothing
        ws = Nothing
        sess = Nothing
 
    End Sub

Open in new window

0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 20428961
I just re-read my post, and realized that I gave you some bad info.  I told you that I always use "Notes.NotesSession" when working with UI classes, but in the code example, I used a mixture of "Lotus.XXX" and "Notes.XXX" objects.

While this works for this specific example, it will not always work.  If you use "Notes.NotesUiWorkspace", you should use "Notes.NotesSession", and not another version of NotesSession.

Here's some background on the two versions:

Notes.NotesSession

 - Reference: "Lotus Notes Automation Classes"
 - It is an OLE object contained in "notes32.tlb".
 - It requires the Notes Client to be running.
 - You can use UI objects.
 - The user will have to enter a password.

Lotus.NotesSession

 - Reference "Lotus Domino Objects"
 - It is a COM object contained in "domobj.tlb".
 - It and does not require the Notes Client to be running.
 - You can NOT use UI objects (back-end only).
 - You can bypass the login prompt by calling NotesSession.Initialize or NotesSession.InitializeUsingNotesUserName.

OK, now that I have that off my chest, here's the revised ComposeNotesMemo function.  I'll pass a version that supports attachments in my next post.
    Public Sub ComposeNotesTextMemo(ByVal Recipient As String, ByVal Subject As String, ByVal BodyText As String)
 
        Dim sess As Object
        Dim ws As Object
        Dim uidoc As Object
        Dim mailServer As String
        Dim mailFile As String
        sess = CreateObject("Notes.NotesSession")
        mailServer = sess.GetEnvironmentString("MailServer", True)
        mailFile = sess.GetEnvironmentString("MailFile", True)
        ws = CreateObject("Notes.NotesUiWorkspace")
        uidoc = ws.ComposeDocument(mailServer, mailFile, "Memo")
        uidoc.FieldSetText("EnterSendTo", Recipient)
        uidoc.FieldSetText("Subject", Subject)
        uidoc.GotoField("Body")
        uidoc.InsertText(BodyText)
        AppActivate("New Memo - Lotus Notes")
        uidoc = Nothing
        ws = Nothing
        sess = Nothing
 
    End Sub

Open in new window

0
 
LVL 22

Accepted Solution

by:
Bill-Hanson earned 500 total points
ID: 20428974
In my last post, I said I'd post a version that supports a file attachment.  Here it is...
    Public Sub ComposeNotesAttachmentMemo(ByVal Recipient As String, ByVal Subject As String, ByVal BodyText As String, ByVal Attachment As String)
        Dim sess As Object
        Dim ws As Object
        Dim uidoc As Object
        Dim doc As Object
        Dim db As Object
        Dim body As Object
        Dim mailServer As String
        Dim mailFile As String
        Const EMBED_ATTACHMENT = 1454
 
        ' Create a temp doc to pull in the attachment.
        sess = CreateObject("Notes.NotesSession")
        mailServer = sess.GetEnvironmentString("MailServer", True)
        mailFile = sess.GetEnvironmentString("MailFile", True)
        db = sess.GetDatabase(mailServer, mailFile)
        doc = db.CreateDocument
        doc.ReplaceItemValue("Form", "Memo")
        body = doc.CreateRichTextItem("Body")
        If (Trim(Attachment) <> "") Then body.EmbedObject(EMBED_ATTACHMENT, "", Attachment)
        doc.Save(True, False)
 
        ' Copy the file to the clipboard.
        ws = CreateObject("Notes.NotesUiWorkspace")
        uidoc = ws.EditDocument(True, doc)
        uidoc.GotoField("Body")
        uidoc.SelectAll()
        uidoc.Copy()
        uidoc.Document.SaveOptions = "0"
        uidoc.Document.MailOptions = "0"
        uidoc.Close()
        doc.Remove(True)
 
        ' Compose the memo.
        uidoc = ws.ComposeDocument(mailServer, mailFile, "Memo")
        uidoc.FieldSetText("EnterSendTo", Recipient)
        uidoc.FieldSetText("Subject", Subject)
 
        ' Paste the link.
        uidoc.GotoField("Body")
        uidoc.InsertText(BodyText & Chr(10) & Chr(10))
        uidoc.Paste()
 
        ' Bring the window to the front.
        AppActivate(uidoc.WindowTitle)
        uidoc = Nothing
        ws = Nothing
        sess = Nothing
    End Sub

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Contestoas
ID: 20429530
Hi Bill
This is REALLY excellent !! I've been banging my head against the keyboard all day trying to figure this one out ....The code looks like just the thing I need !!

It's 7 PM here in europe now so I'll have a go at this on monday!
I'm allso going to use Obejcts but I needed the Intellisense in order to figure out how to do this .......

One last little thing ! (and thanks for supplying code for file attachment as well)
I'm going to attach multiple files, that's no problem right ?

cheers
Peter
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 20429629
Multiple files are not a problem, just modify the code a bit.  Also, if you need to send MIME or you want to use Lotus.NotesSession instead (send only, no compose), just let me know.  I have plenty of examples.
0
 

Author Comment

by:Contestoas
ID: 20448427
This worked just fine Bill !!
Thanks.
Just one more thing .... When I deploy the application I get a SecurityExeption ....
This is .NET 2.0
Do you know what to do in order to trust the assembly I created ?

Peter
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 20449333
You'll need to give all the assemblies in your application a strong name, and modify the security policy to trust this strong name.

See the link below for more info.  It explains how to generate a strong name key pair using the sn.exe tool, how to sign your assemblies, and how to modify the security policy to trust the strong name.

http://blogs.msdn.com/shawnfa/archive/2003/06/20/57023.aspx

0
 

Author Comment

by:Contestoas
ID: 20449505
Well I actually got i t working by deploying it with a setup project. ;-)

Thanks anyway !!!!
Peter
0
 

Author Closing Comment

by:Contestoas
ID: 31413374
Great solution !!!!
0
 
LVL 22

Expert Comment

by:Bill-Hanson
ID: 20449839
I was going to ask about that.  I always use a setup project, and sign my assemblies, so I've never seen the SecurityExeption.
0
 

Author Comment

by:Contestoas
ID: 20449855
Well, me too but this time I just copied the exe application that I created in order to see if this code worked in the production environment .....

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

772 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