Solved

Agent on incoming email

Posted on 2006-06-13
17
359 Views
Last Modified: 2013-12-18
Hello all, can someone help me out??  I want to create an agent the will run against a mail file when new messages are recieved.  Basically it will grab the message, create a new message (to change the from attributes), insert the original body and subject contents, send the new message, delete the originall message.  Its going to turn the mail box into a forwarding box.  I thought I had it but must be missing something.  Its finally to where it will send the message but I can't seem to get the contents of the original message.  I'm probably missing something stupid.  Can someone help me out??? Thanks!!!


Current code:
Sub Initialize
      On Error Resume Next
      Dim Session As New NotesSession
      Dim SendDoc As NotesDocument
      Dim db As NotesDatabase
      Dim doc As NotesDocument
      
      Dim workspace As New NotesUIWorkspace      
      Dim uidoc As NotesUIdocument
      
      Set uidoc = workspace.currentdocument
      
      Set doc = Session.DocumentContext
      Set db = Session.Currentdatabase
      
      Set SendDoc = New NotesDocument(db)
      
      SendDoc.Form = "Memo"
      SendDoc.SendTo = "my.email@zyx.com"
      SendDoc.Subject = "Msg Forward"
      SendDoc.Principal = "message.forward.zyx.com"
      SendDoc.From = "message.forward.zyx.com"
      SendDoc.Body = uidoc.FieldGetText("Body")            
      Call SendDoc.Send(False)             
End Sub

It sends the message but the body is blank!!  Thanks!!
0
Comment
Question by:NARoberts
  • 6
  • 5
  • 2
  • +3
17 Comments
 
LVL 18

Expert Comment

by:marilyng
ID: 16895888
Why no simply change the forwarding address in the NAB? Once you add an address there, anything sent to  abc.xyz.com will be sent, instead to whatever you specify in the forwarding address.  Since you don't need to keep a copy, then there shouldn't be a problem routing it at the router, right?
0
 
LVL 3

Author Comment

by:NARoberts
ID: 16895937
Tried it don't work!!  Its complicated.  I need to trick notes, its too smart for its own good!!!!
0
 
LVL 5

Accepted Solution

by:
pgloor earned 50 total points
ID: 16896266
Sorry, I'm in a hurry. Try this (it's far from being perfect):

Dim SendDoc As NotesDocument
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim uidoc As NotesUIdocument
      
On Error Resume Next
Dim Session As New NotesSession
      
Dim workspace As New NotesUIWorkspace    

Set uidoc = workspace.currentdocument
      
Set doc = Session.DocumentContext
Set db = Session.Currentdatabase
      
Set SendDoc = New NotesDocument(db)

' Copy all items from original memo
Call doc.CopyAllItems(SendDoc, True)

' Overwrite some fields with new values      
SendDoc.SendTo = "my.email@zyx.com"
SendDoc.Subject = "Msg Forward"
SendDoc.Principal = "message.forward.zyx.com"
SendDoc.From = "message.forward.zyx.com"

Call SendDoc.Send(False)
0
 
LVL 20

Expert Comment

by:brwwiggins
ID: 16896312
Is the trigger after new mail arrives or is it from the action menu?

Just trying to figure out why you have the NotesUIDocument in there since that would mean one you have open on your workspace. If this is running on the server then you can't use that.
0
 
LVL 3

Author Comment

by:NARoberts
ID: 16896406
It is running on new mail.....however, it does work  guess because of the on error resume next????
0
 
LVL 3

Author Comment

by:NARoberts
ID: 16896415
I took out the uidoc stuff and its still ok.....thanks for the help guys and the code pgloor!
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 16896426
You can also use a Rule to send a copy, and then delete the original.
Wat Version are you using ?

I hope this helps !
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16897806
>>Tried it don't work!!  << impossible!!  This is idiot proof.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 18

Expert Comment

by:marilyng
ID: 16897812
Brwiggins is right, it doesn't work because you can't use UI/WS commands in the agent.
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16897818
The selected answer is incorrect!!  Because it cannot run on a scheduled agent!!!  
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16900501
As Marilyn says, using uidoc in an agent is impossible. Better to remove those unused lines from the code...
0
 
LVL 3

Author Comment

by:NARoberts
ID: 16901434
Idiot proof????  Maybe you should know the whole story before you answer!!  

I have message disclaimers setup for all users.  However since I am the administrator I get alot of system messages.  Sometimes important stuff like servers going down.  These messages get forwarded to my cell phone.  Thing is w/ a disclaimer a 2 line text message becomes 5 messages and gets rather costly.  I initially tried to create another box w/ a forwarder.  Lotus in trying to be efficient sees the forward and never delivers to the other box (which doesn't have a disclaimer setup) but just reroutes the mail.  Thus you still get disclaimers!!  Soooo as I said, it doesn't work!!!  The code pgloor gave works perfect (even w/ a little extra code).  Thus he gets credit and I'm happy.  
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16901701
What we're saying is that the code won't work in an agent.  It will not send you messages.

Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim doc As NotesDocument
      Dim coll As NotesDocumentCollection
      Dim principal As NotesName
      Dim maildoc As NotesDocument
      Dim rtitem As Variant
      Dim sendToName As String
      Set principal = New NotesName(session.username)
      sendToName = "my.email@zyx.com"
      'First time this runs it will probably send a message for every document in your inbox
      Dim todayDate As New NotesDateTime(Format(Now,"mm/dd/yyyy") + " 12:00:01 AM")
      Call todaydate.AdjustDay (-1)
      
      Set db = session.currentdatabase      
      Set coll = db.unprocesseddocuments
      
      If coll.count>0 Then
            Set doc = coll.getfirstdocument
            While Not doc Is Nothing
                  With doc
                        Set maildoc = New NotesDocument(db)
                        maildoc.sendTo=sendToName
                        Maildoc.from = Principal.abbreviated
                        Maildoc.principal = principal.canonical
                        Maildoc.Subject = "FWD: " + doc.subject(0)
                        Set rtitem = doc.GetFirstItem( "Body" )
                        If ( rtitem.Type = RICHTEXT ) Then
                              'Strip tabs and wrap every 15 characters for cell phone?
                              Maildoc.Body= rtitem.GetFormattedText( True, 15 )
                        Else
                              maildoc.body = rtitem.text
                        End If
                        maildoc.send False
                        Set maildoc = Nothing
                  End With
                  Set doc = coll.getNextDocument(doc)
            Wend            
            Print "Finished processing " + Cstr(coll.count) + " forward documents..."
            Call coll.UpdateAll
      Else
            Print "No documents to process..."
            Call coll.UpdateAll
      End If
      
End Sub


sjef, gotta run.. can you fix the todayDate stuff, so that the agent only processes stuff from the last day, instead of the entire inbox from the past two years?
0
 
LVL 3

Author Comment

by:NARoberts
ID: 16901865
This is what I'm using. It runs just fine as an agent.  It runs "before new mail arrives".

Sub Initialize
      On Error Resume Next
      Dim Session As New NotesSession
      Dim SendDoc As NotesDocument
      Dim db As NotesDatabase
      Dim doc As NotesDocument
      
      Set doc = Session.DocumentContext
      Set db = Session.Currentdatabase
      
      Set SendDoc = New NotesDocument(db)
      
      SendDoc.Form = "Memo"
      
      ' Copy all items from original memo
      Call doc.CopyAllItems(SendDoc, True)
      
      SendDoc.SendTo = "937xxxxxxx@mobile.mycingular.com"
      SendDoc.Subject = "Msg Forward"
      SendDoc.Principal = "NForward"
      SendDoc.From = "NForward"      
      Call SendDoc.Send(False)             
End Sub
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 16901970
Seems okay to me, since you left out all the UI-stuff ;)
I don't really share Marilyn's main concern, that all mail might be reprocessed some day: the agent is triggered "before new mail arrives". She could be right though.

What she also may be after is that you might get only 1 mail when several mails are received at the same time. Can you check that?
0
 
LVL 20

Expert Comment

by:brwwiggins
ID: 16902398
only think I would add is make sure you have a valid reply to address contained in the memo in case of errors or bounce backs.
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16904207
Call doc.CopyAllItems(SendDoc, True) << this also concerns me.  since you only want text sent, you should specify text.  

Without seeing the code you were using and what the trigger was, I didn't know how you were getting all documents that arrive without the uidoc handle that was included in the original code.


If the trigger is before mail arrives, then it should run on each document. Otherwise you have to use the collection object to run on After new mail arrives, or when documents are copied or pasted.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now