10 pts.
 LotusScript to forward mail to recipient in body
I'm looking for a LotusScript to manage mails coming from a specific address, say "me@somewhere.com" and forward the message from my notes-mail to a recipient found in the message body after the word "From:". Ideally I would also like the script to cut all lines in the message between a "£"-sign and the line starting with "From:". Can this be done?

Software/Hardware used:
ASKED: February 5, 2009  11:38 AM
UPDATED: January 16, 2012  7:56 PM

Answer Wiki:
Yes it can be done. You'll need to create an agent that runs after new mail arrives. Then, use UnprocessedDocuments to get the new mail and parse the From and Body fields for the strings you seek. The agent can then create a new mail document with the portion of the body text you want. Then send it and save it or not, depending on whether you want the forwarded message to remain in the mail database. Writing and posting the entire script is probably beyond the scope of this blog, but if someone gets ambitious... ***ADDED 02/06/09*** You might be able to do this with a rule as well, if I could see a copy of an email that will be sent I could tell for sure. Otherwise Ledlincoln is right, it will take some sort of agent - code should not be too difficult. I can help if need be. ***END ADDITION - SlikTool (aka mkinder@acadiasolutions.com)*** ***02/09/09 - Response to SlikTool*** A mail rule won't be able to handle the parsing of the body for the forward-to address. -LedLincoln *************************************************************
Last Wiki Answer Submitted:  February 9, 2009  4:33 pm  by  SlikTool   1,830 pts.
All Answer Wiki Contributors:  SlikTool   1,830 pts. , Ledlincoln   1,620 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Hello LedLincoln,
I am looking for a similar script; one that can just forward all me messages as if I’m being carbon or blind carbon copied on another address. I don’t know any Lotus Script or Java syntax though. Could you help me out? Thanks.
Boris

 20 pts.

 

Boris,
There are all sorts of caveats to go with such an action as forwarding all of your mail outside of your organization, but the basic method can be as simple as
- go to Rules and click New Rule button
- Set condition as you want (sounds like you want “all documents” from the dropdown) and click the Add button
- Set the actions dropdowns to “send copy to” and “full”, enter the destination email address, and click “Add Action”
- Click OK

 2,700 pts.

 

Hi Stiletto,
I have that rule setup already but it would be nice to be able to clean up the forwarded messages so the original sender appears in the forward and the fwd headers are removed in the message. I can’t create private agents in notes, I already tried a lotus script.

 20 pts.

 

Hello LedLincoln,

I have made a script (att below) in an agent that forwards mails; working ok except for:
1. All mails are forwarded twice.
2. Mails sent from database appear as “Sent by: <me>”, and not by original sender or database.

Best regards, Trond

Sub Initialize

Dim session As NotesSession
Dim db As New NotesDatabase( “”, “review.nsf” )
Dim Maildoc As notesdocument
Dim coll As NotesDocumentCollection
Dim doc As NotesDocument
Dim a As Integer
Dim itemBody As NotesItem

Set session = New NotesSession
Set db = session.CurrentDatabase
Set coll = db.UnprocessedDocuments
For a=1 To coll.Count

Set doc=coll.GetNthDocument(a)
Set Maildoc = New NotesDocument(db)
Maildoc.Form = “Memo”
Maildoc.Subject = doc.Subject
Set itemBody = doc.GetFirstItem( “Body” )
Call Maildoc.CopyItem( itemBody, “Body” )
Maildoc.From = “<db-mail>”
Maildoc.Principal = “<db-mail>”
Maildoc.SendTo = “recipient1″
Call Maildoc.Send(False)
Maildoc.SendTo = “recipient2″
Call Maildoc.Send(False)

Next

End Sub

 20 pts.

 

To avoid twice send, replace these 4 lines :

Maildoc.SendTo = “recipient1″
Call Maildoc.Send(False)
Maildoc.SendTo = “recipient2″
Call Maildoc.Send(False)

By :

Dim tabSendTo(1) as variant
tabSendTo(0) = “recipient1″
tabSendTo(1) = “recipient2″
Call Maildoc.Send(False, tabSendTo)

 4,075 pts.

 

Trond,

>1. All mails are forwarded twice.

Well, the code says to send it to “recipient1″ and then it says to send it to “recipient2″, so I would expect it to forward it twice, once to each recipient. Or is that not what you’re experiencing?

>2. Mails sent from database appear as “Sent by: <me>”, and not by original sender or >database.

In the properties box for the agent, go to the second tab and set the “Run on behalf of” field to whatever you want and see if that changes the behavior.

BTW, you should not use GetNthDocument like that; it is incredibly inefficient. Instead, use

Set doc=coll.GetFirstDocument
Do While Not doc Is Nothing
process
doc=coll.GetNextDocument(doc)
Loop

GetNthDocument(x) gets doc #x by starting at the beginning and counting to x. Each time you use it, it starts at the beginning again. So, inside a loop, it starts at the beginning and counts to 1; the next iteration through the loop it starts at the beginning and counts to 2, etc. GetNthDocument is fine if you need to jump to document #37 for some reason (as an example), but other than that, GetFirstDocument/GetNextDocument is probably the better approach.

 2,700 pts.

 

Thanks BruceWayne and Stiletto;

However, mails still appear twice out from this mailbox; in other words the script is called twice (about one minute apart), on the same event. On the properties box for the agent the Trigger is set to “On event” and “After new mail has arrived”. Hmmm….

 20 pts.