send message to all boxes...

Discussion for developers using MailEnable.
Post Reply
sunpost
Posts: 438
Joined: Wed Sep 04, 2002 3:04 pm

send message to all boxes...

Post by sunpost »

this script writes a message to all mailboxes

Code: Select all

<%@ LANGUAGE="VBSCRIPT" %> 
<% Option Explicit %>
<html>
<head>
<title>ME - MailAll</title>
</head>
<body>
<%
If Request.Form("cmdSend") <> "" Then
Dim MyPO
Dim RetPO
Dim MyMB
Dim RetMB
Dim WshShell
Dim MailDataPath
Dim FileNameGUID
Dim MyFSO
Dim MyTextFile
Dim TextFilePath
Dim txtMailMessage 

'get the data directory where the postoffices are loacated
	Set WshShell = Server.CreateObject("WScript.Shell")
	MailDataPath = WshShell.RegRead("HKLM\SOFTWARE\Mail Enable\Mail Enable\Data Directory")

'create a unique file name
	FileNameGUID = Replace(mid(Server.createobject("scriptlet.typelib").guid,2,36),"-","")

	Set MyFSO = Server.CreateObject("Scripting.FileSystemObject")

'create postoffice object
	Set MyPO = Server.CreateObject("MEAOPO.Postoffice")

'set values to postoffice properties
'this will allow iteration using FindNext
	MyPO.Name = ""
	MyPO.Status = -1
	MyPO.Account = ""

'get the first postoffice
	RetPO = MyPO.FindFirstPostoffice()

'iterate thru all postoffices
'***note: i do not know all the return codes
'         in this example 1 was success and 0 was EndOfPostoffices
'         this can(should) change when the return codes are released
	Do While RetPO = 1
		'write the postoffice name(the status and account properties can be written too)
		Response.Write MyPO.Name &  "<br />" & vbCrLf

		'create a mailbox object
		Set MyMB = Server.CreateObject("MEAOPO.Mailbox")
	
		'set values to mailbox properties
		'this will allow iteration using FindNext
		'***note: setting MyMB.Postoffice to MyPO.Name 
		'         instructs FindFirst to use the postoffice value contained in MyPO.Name
		MyMB.Postoffice = MyPO.Name
		MyMB.Mailbox = ""
		MyMB.RedirectAddress = ""
		MyMB.RedirectStatus = -1
		MyMB.Status = -1
		MyMB.Limit = -1
		MyMB.Size = -1
		RetMB = MyMB.FindFirstMailbox()

		'iterate thru all mailboxes
		'***note: i do not know all the return codes
		'         in this example 1 was success and 2 was EndOfMailboxes
		'         this can(should)(i hope) will change when the return codes are released
		'         i was expecting 0 to be returned
		Do While RetMB = 1
			'build path to the current mailbox inbox
			TextFilePath = MailDataPath & "\postoffices\" & MyPO.Name & "\mailroot\" & MyMB.Mailbox & "\inbox\" & FileNameGUID & ".mai"
	
			'write the mailbox name
			Response.Write "--- " & TextFilePath & "<br />" & vbCrLf
		
			'build mail message
			txtMailMessage = "From: " & Trim(Request.Form("txtFrom")) & vbCrLf
			txtMailMessage = txtMailMessage & "To: " &  MyMB.Mailbox & vbCrLf
			txtMailMessage = txtMailMessage & "Subject: " & Trim(Request.Form("txtSubject")) & vbCrLf & vbCrLf 
			txtMailMessage = txtMailMessage & Request.Form("txtMessage")
		
			'create mail message file
   			Set MyTextFile = MyFSO.CreateTextFile(TextFilePath , True)
   			MyTextFile.WriteLine(txtMailMessage) 
   			MyTextFile.Close
   			Set MyTextFile = Nothing
   			
			MyMB.Mailbox = ""
			MyMB.RedirectAddress = ""
			MyMB.RedirectStatus = -1
			MyMB.Status = -1
			MyMB.Limit = -1
			MyMB.Size = -1
			RetMB = MyMB.FindNextMailbox()
		Loop
	
		'clean up the mailbox object
		Set MyMB = Nothing

		MyPO.Name = ""
		MyPO.status = -1
		MyPO.account = ""
		RetPO = MyPO.FindNextPostoffice()
	Loop

	'clean up the postoffice object
	Set MyPO = Nothing
	
	Set MyFSO = Nothing

Else
%>
<form method="POST" name="sendmail" onsubmit="return(confirm('Are You Sure?')?true:false)";>
  From<br />
  <input type="text" name="txtFrom" size="93"><br />
  <br />
  Subject<br />
  <input type="text" name="txtSubject" size="93"><br />
  <br />
  Message<br />
  <textarea rows="15" name="txtMessage" cols="80"></textarea>
  <p><input type="submit" value="Send" name="cmdSend"></p>
</form>
<%End If%>
</body>
</html>

Post Reply