|
|||||||||||||||||||
Sample Code This document provides some
samples written in Visual Basic that show how to achieve certain common
functions. Creating a WorkgroupMail Session and listing usersThis example, shows
how to log on to the WorkgroupMail session and list the WorkgroupMail users Dim sess As Object Dim user As Object Dim users As Object Dim bLoggedOn As
Boolean Set sess =
CreateObject("WMAPI.WMSession") bLoggedOn = sess.Login("adminpassword") Set user = sess.GetFirstUser While not user Is
Nothing MsgBox user.name Set user = sess.GetNextUser(user) Wend Adding a user to WorkgroupMailThis example, shows
how to add a new user to WorkgroupMail and assign the user an e-mail address. Dim sess As Object Dim user As Object Dim bLoggedOn As
Boolean Dim settings As
Object Dim domain As Object Set sess =
CreateObject("WMAPI.WMSession") bLoggedOn = sess.Login("adminpassword") Set user = sess.AddUser("John
Smith") Set domain =
sess.GetFirstDomain If Not domain Is
Nothing Then Set
settings = user.GetDomainSettings(domain) Settings.Mailbox
= "fred.smith" End If Assigning a personal POP account at an ISP for a userThis example follows
on from the previous example. Once a user has been created, it is configured to
collect mail from a personal POP account at the first ISP defined in
WorkgroupMail. Dim ispSettings As
Object Dim isp As Object Set isp =
sess.GetFirstISP Set ispSettings = user.GetISPSettings(isp) ispSettings.POP3LoginName
= "fred123" ispSettings.POP3Password
= "fred123password" Listing the messages in the Incoming queue for a userThis example, shows
how to list the messages that are stored in the incoming queue for a particular
user pending retrieval. Dim sess As Object Dim user As Object Dim bLoggedOn As
Boolean Dim settings As
Object Dim domain As Object Set sess =
CreateObject("WMAPI.WMSession") bLoggedOn = sess.Login("adminpassword") Set user = sess.GetUserByID(5) If Not user Is
Nothing Then Set
msgs = user.GetReceivedMessages Set
msg = msgs.GetFirstMessage While
Not msg Is Nothing MsgBox msg.subject Set msg = msgs.GetNextMessage(msg) Wend End If Listing the messages in the Incoming queue for all usersThis example, shows
how to list the messages that are stored in the incoming queue for all users. Dim sess As Object Dim user As Object Dim bLoggedOn As
Boolean Dim settings As
Object Dim domain As Object Set sess =
CreateObject("WMAPI.WMSession") bLoggedOn = sess.Login("adminpassword") Set msgs = sess.GetReceivedMessages Set msg =
msgs.GetFirstMessage While Not msg Is
Nothing MsgBox
msg.subject Set
msg = msgs.GetNextMessage(msg) Wend Sending a messageThis example, shows
how to send a message. Dim sess As Object Dim user As Object Dim bLoggedOn As
Boolean Set sess =
CreateObject("WMAPI.WMSession") bLoggedOn = sess.Login("adminpassword") Set msg = sess.NewMessage Call msg.SetSender("Fred Bloggs", "fred.bloggs@domain.com") Call msg.AddRecipient("John Doe", "john.doe@hotmail.com") Call msg.SetSubject("This is the subject") Call msg.SetMessageText("This is the body of the message") Call msg.SendUsingSMTP("192.168.0.1", 25) 'Where 192.168.0.1 is the IP address of the computer running WorkgroupMail. |
|||||||||||||||||||