Lotus script實現讀多個郵件,併合並在一起發出去

Dim session As NotesSession
Dim db As NotesDatabase
Dim emaillog As NotesLog

Const SUBJECT = "MQ Monitor mail: "

Const Mailstart = "Dear all,"
Const mailSignature = "Your sincerely"

Const LOGMAILSUBJECT = "MQ Monitor generator tool status log"

Const ROWS = 8
Const COLS = 1

Dim folders(8) As String
Dim subjects(8) As String 
Dim lables(8) As String


%REM
 Sub InitializeVariables
 Description: Comments for Sub
%END REM
Sub InitializeVariables
 
 emaillog.logAction("Start of InitializeVariables.")
 
 folders(0) = "CHECK"
 folders(1) = "CHECK"
 folders(2) = "CHECK"
 folders(3) = "CHECK"
 folders(4) = "CHECK"
 folders(5) = "CHECK"
 folders(6) = "MQMonitorConfig"
 folders(7) = "MQMonitorConfig"
 
 subjects(0) = "hub_check"
 subjects(1) = "info_check"
 subjects(2) = "Check (GHO)"
 subjects(3) = "Gateway check"
 subjects(4) = "Hourly_Status"
 subjects(5) = "MQ Status Check"
 subjects(6) = "Failed Queue Depth History"
 subjects(7) = "Guide & Attention"
 
 lables(0) = "ACheck"
 lables(1) = "BCheck"
 lables(2) = "CCheck"
 lables(3) = "DCheck"
 lables(4) = "ECheck"
 lables(5) = "FCheck"
 lables(6) = "Failed Queue Depth History"
 lables(7) = "Guide & Attention" 

 emaillog.logAction("End of InitializeVariables.")
 
End Sub

 

Sub Initialize
 
 Set session = New NotesSession
 Set db = session.CurrentDatabase
 
 REM Create a email log
 Set emaillog = New NotesLog("email log")
 Call emaillog.openMailLog(session.UserName, LOGMAILSUBJECT)
 emaillog.logAction("Start of Agent.") 
 
 Call InitializeVariables
 
 Call SendMQMonitorMail
 
 emaillog.logAction("End of Agent.")
 
End Sub

Sub Terminate
 emaillog.close
End Sub

%REM
 Function SendMQMonitorMail
 Description: Comments for Function
%END REM
Sub SendMQMonitorMail
 
 emaillog.logAction("Start of SendMQMonitorMail......")
 
 emaillog.logAction("The user name is: " & session.CommonUserName )
 emaillog.logAction("The user id is: " & session.UserName )
 
 REM Create a notes mail
 Dim doc As New NotesDocument(db)
 Call doc.AppendItemValue("From", session.UserName)
 Call doc.AppendItemValue("Form", "Main Form")
 
 REM Set subject with timestamp
 
 Call doc.AppendItemValue("Subject", SUBJECT & GetGMTTime)
 
 emaillog.logAction("mail document created successfully.")
 
 Dim body As New NotesRichTextItem(doc, "Body")
 Call body.AppendText(Mailstart)
 
 Call body.AddNewLine(2)
 
 
 Call body.AppendText("    Working fine?")
 Call body.AddNewLine(2) 
 
 REM Create table
 Call body.AppendTable(ROWS, COLS, lables)
 
 emaillog.logAction("Table created successfully.")
  
 Dim rtnav As NotesRichTextNavigator
 Set rtnav = body.CreateNavigator
 Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
 
 REM Set content of table cells
 emaillog.logAction("Start to set content of table cells.")
 Dim i As Integer
 For i% = 1 To ROWS
  
  emaillog.logAction("Generating content for lable: " & lables(i - 1))
  Call body.BeginInsert(rtnav)
  Call body.AppendText(getMailContent(folders(i - 1), subjects(i - 1)) )
  Call body.EndInsert
  Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
  
 Next
 
 REM Set mail signature         
 Call body.AddNewLine(2) 
 Call body.AppendText(mailSignature)
 Call body.AddNewLine(2) 
 
 emaillog.logAction("Sending mail......")
 Call doc.send(True, session.UserName)
 
 emaillog.logAction("End of SendMQMonitorMail.")
End Sub

%REM
 Function GetMailContent
 Description: Comments for Function
%END REM
Function GetMailContent(ByVal viewName As String, ByVal subject As String) As String
 
 emaillog.logAction("Start of getMailContent.")
 Dim view As NotesView
 Set view = db.GetView(viewName)
  
 Dim doc As NotesDocument
 Set doc = view.Getfirstdocument()

 Dim mailContent As String
  
 If doc.HasItem("Subject") Then
  While Not(doc Is Nothing)
   Dim subj As NotesItem
   Set subj = doc.GetFirstItem("Subject")
  
   If subj.text = subject Then
       emaillog.logAction("Found the subject:" & subject)
      
    Dim body As NotesRichTextItem
    Set body = doc.GetFirstItem("Body")

       mailContent = body.Text
   
       GoTo endofMailcontent
     
      End If
  
      Set doc = view.GetNextDocument(doc)
  
  Wend
  
 End If

endofMailcontent: 
 emaillog.logAction("End of getMailContent.")
 GetMailContent = mailContent
 
End Function

 

%REM
 Function GetGMTTime
 Description: Comments for Function
%END REM
Function GetGMTTime() As String
  
 Dim dateTime As NotesDateTime
 Set dateTime = session.CreateDateTime(Time()) 
  
 GetGMTTime = dateTime.GMTTime
 
End Function

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章