Home > Domino Tips > Developer > LotusScript > Good mail forwarding agent
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Good mail forwarding agent


Steve Pitcher
12.06.2004
Rating: -3.61- (out of 5) Hall of fame tip of the month winner


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


View member feedback to this tip.

The following agent makes a copy of a new e-mail, strips it of the CC and BCC fields (to prevent duplicate e-mails to people), inserts the original "Send to" field and then sends the e-mail to any e-mail address specified. This lets a user see who the original sender is. Otherwise, if you're forwarding e-mails to a handheld, the "From" field will always be you.

This new e-mail will also contain a "Header" that gives the user additional information (original recipient, recipients who were copied on the original e-mail, etc.)

This agent must run on the "Before New Mail Arrives" event. Also, set the runtime security level to "2."

Have fun.

Sub Initialize
 Dim s As New NotesSession
 Dim db As NotesDatabase
 Dim doc As NotesDocument
 Dim forward As NotesDocument
 Dim forwardaddress As String
 Dim rtitem As NotesRichTextItem
 Dim rtnav As NotesRichTextNavigator
 
 forwardaddress = "recipient@test.com"
 'set to the address that you would like 
to forward mail to
 Set db = s.currentdatabase
 Set doc = s.DocumentContext
 
 Set forward = New NotesDocument(db)
 Call doc.CopyAllItems(forward, True)
 Set rtitem = forward.GetFirstItem( "Body" )
 Dim newtext As String
 
 Set rtnav = rtitem.CreateNavigator
 Call rtnav.FindFirstElement(RTELEM_
TYPE_TEXTPARAGRAPH) 'navigation element in 
order to place header in front of body text
 
 Dim nn As New NotesName(doc.
GetItemValue("From")(0)) 'determines if this is 
an internal message or not
 Dim cc As New NotesName(doc.
GetItemValue("CopyTo")(0))  
 Dim sto As New NotesName(doc.
GetItemValue("SendTo")(0)) 
 
 
'Set up a header that will be attached 
to the email which specifies additional 
info about the original email
 Dim testcopy As String
 If doc.GetItemValue("CopyTo")(0) = "" Then
  testcopy = "no one."
 Else
  
  Forall x In doc.GetItemValue("CopyTo")
   If testcopy = Null Then
    testcopy = x
   Else
    testcopy = testcopy + x + ", "
   End If
   
  End Forall
  
 End If
 
 
 If nn.IsHierarchical Then 'if it is then get 
their internet address
  If nn.Addr821 <> Null Then 'if they 
have one then use this as the from 
address
   
   Call rtitem.BeginInsert(rtnav)
   Call rtitem.AddNewLine( 1 )
   Call rtitem.AppendText( "Original message 
sent to " + sto.Addr821 + " and 
copies were sent to " + testcopy)
   Call rtitem.AddNewLine( 3 )
   Call rtitem.EndInsert
   
   Call forward.RemoveItem("CopyTo")
   Call forward.RemoveItem("BlindCopyTo")
   Call forward.ReplaceItemValue
("From", nn.Addr821)
   Call forward.Save( True, True )
   
  Else
   Call rtitem.BeginInsert(rtnav)
   Call rtitem.AddNewLine( 1 )
   Call rtitem.AppendText( "Original message 
sent to " + sto.Addr821 + " and 
copies were sent to " + testcopy)
   Call rtitem.AddNewLine( 3 )
   Call rtitem.EndInsert
   
   Call forward.RemoveItem("CopyTo")
   Call forward.RemoveItem("BlindCopyTo")
   Call forward.ReplaceItemValue("iNetFrom",
 nn.Addr821)
   Call forward.Save( True, True )
  End If 'otherwise if this is an internal
 message and the internet address of 
that user is not populated, use the agent 
signer's return address
 Else 
  Call rtitem.BeginInsert(rtnav)
  Call rtitem.AddNewLine( 1 )
  Call rtitem.AppendText( "Original message 
sent to " + doc.GetItemValue
("SendTo")(0) + " and copies were sent to " 
+ testcopy)
  Call rtitem.AddNewLine( 3 )
  Call rtitem.EndInsert
  
  Call forward.RemoveItem("CopyTo")
  Call forward.RemoveItem("BlindCopyTo")
  Call forward.ReplaceItemValue("iNetFrom", 
doc.GetItemValue("From")
(0)) 'otherwise this came in from the internet, 
so just use the from address 
as the inetfrom
  Call forward.Save( True, True )  
 End If
 forward.Send False, forwardaddress 
 Call forward.RemovePermanently(True)
 
End Sub

MEMBER FEEDBACK TO THIS TIP

It's a great script, but is there a possibility to forward without an attachment?

—Ronald V.

******************************************

I haven't tested this, but this may work with a little modification. This routine checks for embedded objects and then deletes them.

  If forward.HasEmbedded Then 
    Forall x In forward.EmbeddedObjects 
      call x.remove 
    End Forall 
  Else

—Steve Pitcher, tip author

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Steve Pitcher. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
LotusScript
Create a non-specified date picker with LotusScript code
LotusScript accesses clipboard to view copied Notes documents
LotusScript action button manages Lotus Notes mail files
LotusScript sorts a Lotus Notes document collection
Display Lotus Notes user group membership details in a tree view
Alternate version of @Command forwards subform via LotusScript
Process large arrays in Notes forms without undue coding or testing
How to use LotusScript to modify a Lotus Notes view selection
Display a custom message box using a LotusScript-generated button
Debug Lotus Notes documents using extracted data

LotusScript
Customize the principal field of outgoing email messages
Create a non-specified date picker with LotusScript code
Resolve Notes 8 migration error: 'Database has not been opened yet'
LotusScript accesses clipboard to view copied Notes documents
LotusScript action button manages Lotus Notes mail files
LotusScript sorts a Lotus Notes document collection
Display Lotus Notes user group membership details in a tree view
Alternate version of @Command forwards subform via LotusScript
Process large arrays in Notes forms without undue coding or testing
How to use LotusScript to modify a Lotus Notes view selection

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts