Manage Learn to apply best practices and optimize your operations.

Setup a complete mail forwarding solution

Ever have a user request to forward their email and keep a copy on the server? When you setup a forwarding agent using simple actions, all the email comes from the person who setup the forwarding agent. It also has no safeguards for endless loop delivery failures. Well your troubles are over. This tip will tell you how to setup a system that will allow the end user to manage and forward their own mail. It also comes with enhanced features such as forwarding the mail from the person who sent it and skipping nasty delivery failures that could end up in an endless loop.

This requires you to customize the mail template. To do this you will need to add a tab in the (Calendar Profile) form entitled forwarding. On this tab, add the following fields:

Forward_Address - This is an editable text field where the user can type in a forwarding address.

Delete_Mail - This is a radio button field with two options [Save a copy of mail on Server account][Do not save a copy of mail on Server account]

Forward_Enable - This is a radio button with the Refresh fields on keyword change option selected. When the keyword is selected it executes the following formula:

@If(Forward_Enable = "1";@Command([ToolsRunMacro];"(Enable Forwarding)");@Command([ToolsRunMacro];"(Disable Forwarding)"))

This executes an agent that enables or disables the forwarding agent.

Create The above agents using the following code:

@Command( [AgentEnableDisable] ; "Forward Mail" ; "1" ) Note: Use a '1' to enable or a '0' to disable.

Setup an agent that executes before email arrives and paste the following code into it:

Sub Initialize
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim doc As NotesDocument
    Dim mdoc As NotesDocument
    Dim item As NotesItem
    Dim recipient As String
    Dim deletemail As String
    Dim pdoc As NotesDocument
    Dim agentLog As New NotesLog("Agent log")
    Call agentLog.OpenAgentLog
    Call agentLog.LogAction("SendMemo routine begin")
    Set db = s.CurrentDatabase
    Dim mailbox As New NotesDatabase("","")
    Call mailbox.Open(db.server,"") ' Get handle to on the users current mail server
    Set doc = s.DocumentContext
    Set pdoc = db.GetProfileDocument("Calendar Profile")
    If Not pdoc Is Nothing Then
       recipient = pdoc.Forward_Address(0)
       'Check to see if they want the mail deleted from the server copy
       deletemail = pdoc.Delete_Mail(0)
       Call agentLog.LogAction("Recipient = " & recipient)
    End If
    If Not doc Is Nothing Then
       'Make sure the doc is not a Delivery Failure
       If doc.form(0) <> "NonDelivery Report" Then
           Call agentLog.LogAction("doc found")
           Set mdoc = mailbox.CreateDocument
           mdoc.form = "Memo"
           mdoc.subject = doc.subject(0)
           If doc.from(0) <> "" Then
                 mdoc.from = doc.from(0)
                 mdoc.principal = doc.from(0)
                 mdoc.SendFrom = doc.from(0)
                 Call agentLog.LogAction("Sender = " & doc.from(0))           Else
                 mdoc.from = doc.principal(0)
                 mdoc.principal = doc.principal(0)
                 mdoc.SendFrom = doc.principal(0)
                 Call agentLog.LogAction("Sender = " & doc.principal(0))
          End If
          mdoc.PostedDate = Now()
          mdoc.ComposedDate = Now()
          mdoc.DeliveryDate = Now()
          mdoc.sendto = recipient
          mdoc.Recipients = recipient           Set item = doc.GetFirstItem("Body")
          Call item.CopyItemToDocument( mdoc, "" )
          Call agentLog.LogAction("creating copy in db")
          Call mdoc.Save(True,False) ' Save the document in the ( simulates a send)
          If deletemail = "Do not save a copy of mail in SLOC account" Then
                 Call doc.Remove(True)
           End If
       End If
    End If
End Sub

Dig Deeper on Domino Resources - Part 6

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...