Home > Domino Tips > Developer > Other > Access Notes Mail dynamically via VB 6.0 executable
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

OTHER

Access Notes Mail dynamically via VB 6.0 executable


Andrew Young
06.16.2003
Rating: -4.22- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Create a standard .exe in VB. Add a multi-value list box field, "List1". Add two text fields, "Text1", and "Text2". Make sure the form is named "Form1". Make sure there is an empty label named "Label4", and a command button, "Command1". Beneath the command button, place a frame, call it "Frame2". The caption is also blank. Inside it put another blank label, "Label5". "Label1" should be next to the list box and captioned "Recipient(s)". Label2 should be next to text field Text1 and Captioned "Subject". Label3 should be next to text field Text2 and captioned "Message:". This .exe will access your Notes environment dynamically and will identify your domain, mail file, mail server, and populate a list of everyone in your dom.directory at runtime. Then you can actually send mail from it.



Code

Paste this into General Declaration of the form: Dim s As Object

Then select all and overwrite with this:

Private Sub Command1_Click()
Dim locationDb As Object
Dim locationView As Object
Dim locationDoc As Object
Dim mailDb As Object
Dim mailDoc As Object
Dim currentUser As String
Dim thisLocation As String
Dim mailServer As String
Dim mailFile As String
Set locationDb = s.GetDatabase("", "names.nsf")
Set locationView = locationDb.GetView("Locations")
Set locationDoc = locationView.GetFirstDocument
thisLocation = getLocation()

While Not (locationDoc Is Nothing)
            If locationDoc.GetItemValue("Name")(0) = thisLocation 
Then
                mailServer = getMailServer(locationDoc)
                mailFile = getMailFile(locationDoc)
                Set mailDb = s.GetDatabase(mailServer, mailFile)
            End If
            Set locationDoc = locationView.GetNextDocument
(locationDoc)
Wend
Set mailDoc = mailDb.CreateDocument
Call mailDoc.ReplaceItemValue("SendTo", Form1.List1.Text)
Call mailDoc.ReplaceItemValue("Subject", Form1.Text1.Text)
Call mailDoc.ReplaceItemValue("Body", Form1.Text2.Text)
Call mailDoc.Send(False)
MsgBox "Mail has been sent.", 0 + 64, "Message Sent"
Form1.Text1.Text = ""
Form1.Text2.Text = ""
End Sub

Private Sub Form_Load()
Call Load_Domino
Call Build_Form
End Sub

Public Sub Load_Domino()
Set s = CreateObject("Lotus.NotesSession")
s.Initialize
End Sub
Function getLocation() As String
'get current location and return
currentLocation = s.GetEnvironmentString("Location", True)
myPos = InStr(1, currentLocation, ",", 1)
getLocation = Left(currentLocation, myPos - 1)
End Function
Function getMailServer(locationDoc As Object) As String
getMailServer = locationDoc.GetItemValue("MailServer")(0)
End Function
Function getMailFile(locationDoc As Object) As String
getMailFile = locationDoc.GetItemValue("MailFile")(0)
End Function


Public Sub Build_Form()
Dim namesDb As Object
Dim namesView As Object
Dim nameDoc As Object
Dim locationDb As Object
Dim locationView As Object
Dim locationDoc As Object
Dim mailDb As Object
Dim currentUser As String
Dim thisLocation As String
Dim mailServer As String
Dim mailFile As String
Dim notesDomain As String
Dim myPos As Integer
Dim fileSize As Double

Set locationDb = s.GetDatabase("", "names.nsf")
Set locationView = locationDb.GetView("Locations")
Set locationDoc = locationView.GetFirstDocument
thisLocation = getLocation()

While Not (locationDoc Is Nothing)
            If locationDoc.GetItemValue("Name")(0) = 
thisLocation Then
                notesDomain = locationDoc.GetItemValue
("Domain")(0)
                mailServer = getMailServer(locationDoc)
                mailFile = getMailFile(locationDoc)
                Set mailDb = s.GetDatabase(mailServer, mailFile)
                fileSize = mailDb.Size
            End If
            Set locationDoc = locationView.GetNextDocument
(locationDoc)
Wend

Set namesDb = s.GetDatabase(mailServer, "names.nsf")
Set namesView = namesDb.GetView("people")
Set nameDoc = namesView.GetFirstDocument
currentUser = s.CommonUserName
Form1.Label4.Caption = "Listing of all users in the " & 
notesDomain & " Domain:"
Form1.Frame2.Caption = currentUser & " -- 
Lotus Notes Mail Information"
Form1.Label5.Caption = "Mail Server: " & mailServer & Chr(10) _
& "Mail File: " & mailFile & Chr(10) _
& "Mail File Size: " & CStr(fileSize) & " bytes."

While Not (nameDoc Is Nothing)
If nameDoc.GetItemValue("MiddleInitial")(0) <> "" Then
StrName = nameDoc.GetItemValue("FirstName")(0) & " " & _
          nameDoc.GetItemValue("MiddleInitial")(0) & " " & _
          nameDoc.GetItemValue("LastName")(0)
 Else
   StrName = nameDoc.GetItemValue("FirstName")(0) & " " & _
             nameDoc.GetItemValue("LastName")(0)
End If
Form1.List1.AddItem (StrName)
Set nameDoc = namesView.GetNextDocument(nameDoc)
Wend

End Sub

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Other
Create a dynamic user-driven navigator for a Notes/Domino application
How to apply XSL style sheets to XML views
Comparing replicas on clustered Lotus Domino servers
Creating a Lotus Notes view column categorized by month
Using the XMLHTTP object for integration with Domino or any RDBMS back end
Hiding field properties/data from DocProperties box
Export a view to Excel without coding
Prevent document deletion if there are response documents
Switching between test IDs quickly
AddParameter to a NotesXSLTransFormer

LotusScript
LotusScript finds the first occurrence of a string from the right
Clear Recent Contacts view and prevent repopulation in Lotus Notes 8.x
Search Microsoft Active Directory with LotusScript
Three steps to trap and handle save conflicts with LotusScript
Troubleshoot agents by displaying LotusScript variables online
LotusScript sorts lists alphabetically
Run or restart Notes/Domino agents via text messages
LotusScript code rebuilds corrupted busytime.nsf file
Soft-code item names to facilitate LotusScript management
LotusScript agent automates selective mail file replication

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts