• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1327
  • Last Modified:

Creating Lotus Notes mail and displaying it using .NET

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
Contestoas
Asked:
Contestoas
  • 6
  • 5
1 Solution
 
Bill-HansonCommented:
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
 
Bill-HansonCommented:
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
 
Bill-HansonCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ContestoasAuthor Commented:
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
 
Bill-HansonCommented:
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
 
ContestoasAuthor Commented:
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
 
Bill-HansonCommented:
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
 
ContestoasAuthor Commented:
Well I actually got i t working by deploying it with a setup project. ;-)

Thanks anyway !!!!
Peter
0
 
ContestoasAuthor Commented:
Great solution !!!!
0
 
Bill-HansonCommented:
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
 
ContestoasAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now