Manage Learn to apply best practices and optimize your operations.

Forwarding email messages to other account

This bit of code lets you "forward" an email to another email account while retaining the original Subject and From fields.

VIEW MEMBER FEEDACK TO THIS TIP

There are times when employees need to forward company e-mails to a home/other account. The standard Notes "Send Mail Message" with "Include copy of document" does not make it easy to determine the original sender and subject. This bit of code lets you "forward" to another e-mail account while retaining the original Subject and From fields. The agent can be set to run Before New Mail Arrives.

Sub-initialize
      Dim session As NotesSession
      Set session = New NotesSession
      Dim db As notesdatabase
      Dim Maildoc As notesdocument
      Set db = session.CurrentDatabase
      Dim doc As NotesDocument
      Set doc = session.DocumentContext
      Set Maildoc = New NotesDocument( db )
      Call doc.CopyAllItems( Maildoc, True )    
      Maildoc.From =  doc.From(0)
      Maildoc.Principal =  doc.From(0)
      Maildoc.SendTo =
 "MyHomeAddress@myhomeaccount.com"
      Call Maildoc.Send(True)
End sub

MEMBER FEEDBACK TO THIS TIP

This is a nice tip and a nice idea. However, on my site (Notes 5.09a) it works only properly for Notes-Mail.
For SMTP-mail I get the message "Notes Error: Encryption key not found (mail database is not encrypted on the server)."
On the server console I get the message "> 25.05.2005 10:27:00 AMgr: Agent ('Mail2Home' in 'mail\kossi.nsf') Fehlermeldung (Error Message): Object variable not set"
Any ideas?
—Michael K.

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

 

The Rules feature of Notes can also be customized to forward e-mails to another account [particularly useful for those without Designer access], as follows:

Go to Tools, Mail Rules and choose New Rule.

Under Specify Conditions, create Condition When: Sender does not contain!.

Click Add to put condition into the window When mail messages arrive that meet these conditions:

Under Specify Actions, specify "send copy to" "full," with user's forwarding address in the To: field.

Click "Add Action" to put 'send full copy to [username@domain.dom]' action into 'Perform the following actions:' window.

Click OK.

Enable or Disable the rule as needed by choosing the appropriate button.


—Mira B. 

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

This tip did not work in our setup (Domino 5.0.13, clients in 5.0.11), so I altered it and it works like a charm for us. I added to the doc.principal, doc.inetfrom and doc.replyto fields. Here's the code:

Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim collection As NotesDocumentCollection
      Dim memo As NotesDocument
      Dim doc As NotesDocument
      Dim j As Integer
      Set db = session.CurrentDatabase

      Set collection = db.UnprocessedDocuments

      For j = 1 To collection.Count
            Set memo = collection.GetNthDocument( j )
            If Not( memo.SentByAgent ) Then
                  Set doc = New NotesDocument( db )
                  doc.Form = "Memo"
                  doc.Subject = memo.Subject( 0 )
                  doc.Body = memo.Body
                  doc.Principal = memo.from(0)
                  doc.InetFrom = memo.SMTPOriginator
                  doc.ReplyTo = memo.from(0)

                                  Call doc.Send( True, "Enter your
forwarding address here" )
                  'Call doc.Send( False,
 "Put another EMail address here" )
            End If
            Call session.UpdateProcessedDoc( memo )
      Next
End Sub


—Robert B.

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

I have encountered problems with using a forwarding agent and before mail arrives execution. If there is a high volume of mail it only processes 70% of the mails. I would suggest having it run as a scheduled agent and set a processed flag on the document to know what has been processed. I have had much better luck with this method.
—Pablo H. 

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

I suspected this was probably the solution you'd come up with, based on the abstract. A minor suggestion, however, having implemented virtually the same code myself.

Sub-initialize 
      Dim session As NotesSession 
      Set session = New NotesSession 
      Dim db As notesdatabase 
      Dim Maildoc As notesdocument 
      Set db = session.CurrentDatabase 
      Dim doc As NotesDocument 
      Set doc = session.DocumentContext 
      Set Maildoc = New NotesDocument( db ) 
      Call doc.CopyAllItems( Maildoc, True )     
      Maildoc.From =  doc.From(0) 
      Maildoc.Principal =  doc.From(0) 
      Maildoc.SendTo = 
"MyHomeAddress@myhomeaccount.com

Somewhere after the CopyAllItems you want to remove whatever may have been in the incoming CopyTo field. Otherwise, if you were copied on the original message, you will send a new copy to yourself (and any others copied), and the cycle will continue....

      Maildoc.CopyTo = "" 

      Call Maildoc.Send(True) 
End sub


—John D. 

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

I can't get this to work with mail coming in from outside e-mail addresses. My Domino server reports, "Notes Error: The cryptographic key was not found." Does it only work for incoming Domino mail?
—Jeffery H.

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

The short, quick answer is that it works for us on all e-mail. Whether it comes from another Domino user, Hotmail, Yahoo, etc., it doesn't make any difference in our shop.

The message regarding "cryptographic key" sounds like you have an option in your mail formatting that is different from what we're doing here. I've never encountered any error or warning message involving cryptographic keys. This option worked for us in R5 and R6. I'd be curious to know what you're using.

The next thing I'd check would be whether or not the e-mails were encrypted, or if your company encrypts incoming e-mails. We don't encrypt e-mails as a rule in our shop, so I've never tested the performance using encrypted e-mails.
—Wade Gilliland, tip author

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

Changing the line code

---- Call Maildoc.Send(True)

to

---- Call Maildoc.Send(False)

should cure the "Notes Error: The cryptographic key was not found." problem.

Moreover the document needs to be saved before sending otherwise the recipients specified in the SendTo item are not picked up. Something like:-

----- Call Maildoc.Save(False,False)

Or even better the recipients can be specified directly in:-

----- Call Maildoc.Send(False," 
recipient@recipientaddress")


—Stefano D.

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

This tip was submitted to the SearchDomino.com tip exchange by member Wade Gilliland. 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.
 

This was last published in April 2005

Dig Deeper on Lotus Notes Domino Agents

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchDataCenter

SearchContentManagement

Close