Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating Lotus Notes mail and displaying it using .NET

Posted on 2007-12-07
11
Medium Priority
?
1,322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

609 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