Solved

Creating Lotus Notes mail and displaying it using .NET

Posted on 2007-12-07
11
1,318 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 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 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