
SMTP
Automatically Update Valid Internet Addresses Field in Server Config Doc
Patty Halsey 01.29.2001
Rating: -3.60- (out of 5)




In order to force incoming smtp mail to only accept mail based on the standard, the "Allow messages intended only for the following internet addresses:" needs to be populated with all addresses a company wants to use. However updating this manually is not an acceptable way to insure it's validity 100% of the time. This agent goes through all person documents, mail-in database documents, and group documents and extracts all internet addresses and then writes them to the field in the server configuration document. We had to add an InternetAddress field to the group document and if a person needs to receive e-mail by more than one address, we also check the FullName field for this. Run this agent scheduled as often as desired to keep the config doc up to date.
Code
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim pview As NotesView 'people
Dim gview As NotesView ' groups
Dim mdbview As NotesView ' mail-in dbs
Dim cview As NotesView ' config docs
Dim pdoc As NotesDocument
Dim gdoc As NotesDocument
Dim mdbdoc As NotesDocument
Dim cdoc As NotesDocument
Dim addrarray() As String
Dim i As Integer
Set db = session.CurrentDatabase
i = 0 ' start array counter
' Process the person documents
Set pview = db.GetView("People")
Set pdoc = pview.GetFirstDocument
While Not(pdoc Is Nothing)
If pdoc.HasItem("InternetAddress") Then ' check existance of internet address field
Redim Preserve addrarray(i)
addrarray(i) = pdoc.GetItemValue("InternetAddress")(0) ' write to array
i = i + 1 ' increment array counter
End If
Forall x In pdoc.GetItemValue("FullName") ' loop through all entries in full name field
If Instr(1, x, "@") > 0 Then ' check for an internet address
Redim Preserve addrarray(i)
addrarray(i) = x 'write to array
i = i + 1 ' increment array counter
End If
End Forall
Set pdoc = pview.GetNextDocument(pdoc)
Wend
' Process the group documents
Set gview = db.GetView("Groups")
Set gdoc = gview.GetFirstDocument
While Not(gdoc Is Nothing)
If gdoc.HasItem("InternetAddress") Then ' check existance of internet address field
Redim Preserve addrarray(i)
addrarray(i) = gdoc.GetItemValue("InternetAddress")(0) ' write to array
i = i + 1 ' increment array counter
End If
Set gdoc = gview.GetNextDocument(gdoc)
Wend
' Process the mail-in db documents
Set mdbview = db.GetView("Mail-In Databases")
Set mdbdoc = mdbview.GetFirstDocument
While Not(mdbdoc Is Nothing)
If mdbdoc.HasItem("InternetAddress") Then ' check existance of internet address field
Redim Preserve addrarray(i)
addrarray(i) = mdbdoc.GetItemValue("InternetAddress")(0) ' write to array
i = i + 1 ' increment array counter
End If
Set mdbdoc = mdbview.GetNextDocument(mdbdoc)
Wend
' Get and update config document
Set cview = db.GetView("Configurations")
Set cdoc = cview.GetFirstDocument
' If address book has more than one config doc, or more than one server receiving smtp mail,
' this has to be changed to find the one(s) needing updating.
Set cdoc.AllowMailForInternetAddresses = cdoc.ReplaceItemValue("AllowMailForInternetAddresses", Fulltrim(addrarray))
' and remove empty items in array
Call cdoc.Save( True, True )
End Sub
 |

|
|
 |
|
 |