I feel so stupid.
I’m trying to do a simple thing (I think) and I’ve tried so many variations of things I’ve found here and in ‘help’, I’m getting more confused…
I have an agent that runs when ‘new mail arrives’. If the new mail is a delivery failure, I want to send it to another mailbox. So I’m using
Call doc.Send( False, “PersonA@XYZ.com”)
But it doesn’t keep the delivery failure information when it sends it (as it does if you would manually ‘forward’ it).
So I simply want to add the field OriginalSubject to the Body of the field before sending it.
So Body is RichText, OriginalSubject is Text. Exactly what ‘append’ do I use? I’ve tried so many combinations and I always end up with type mismatch!
Here’s my most recent…I’ve tried itemA(0) and ItemA, doc.subject and doc.subject(0), and Set rtitemB = doc.GetFirstItem( “OriginalSubject” ) …etc. etc.
I just bet someone knows this off the top of their head!
Dim itemA As Variant
Dim rti As NotesRichTextItem
Set itemA = doc.subject
Call rti.AppendText(itemA(0))
Subject: Add text field into the Body of an email … help!
Dim rti As VariantDim uidoc As NotesUIDocument
Dim ws As New NotesUIWorkspace
Dim adoc As NotesDocument
…
…
Set uidoc = ws.CurrentDocument
set rti=uidoc.document.GetFirstItem(“Memo”)
Set adoc = New NotesDocument(db)
adoc.Subject = uidoc.Document.MemoSubject(0)
Call rtitem.copyitemtodocument(adoc,“Body”)
Call adoc.Send(False,doc.Name(0)) '//username
Subject: incorporating your code…
Here’s where I get stuck inforporating your code…setting the uidoc…
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim unprocessedDocs As NotesDocumentCollection
Dim doc As NotesDocument
Dim doc2 As NotesDocument
Dim db2 As New NotesDatabase( "testserver", "test.nsf" )
Dim rti As Variant
Dim uidoc As NotesUIDocument
Dim ws As New NotesUIWorkspace
Dim adoc As Notesdocument
Set db = session.CurrentDatabase
Set unprocessedDocs = db.UnprocessedDocuments
If unprocessedDocs.Count = 0 Then
Exit Sub
End If
Set doc = unprocessedDocs.GetFirstDocument()
Do While Not (doc Is Nothing)
If doc.form(0) Like "*NonDelivery Report*" Then
Set uidoc = doc
Set rti = uidoc.document.getfirstitem("memo")
Set adoc = New NotesDocument(db)
adoc.subject = uidocument.memoSubject(0)
Call rti.copyitemtodocument(adoc,"Body")
Call adoc.Send( False, "test@test.com")
Call doc.PutInFolder( "Forwarded Delivery Failures" )
Call doc.Removefromfolder("$Inbox")
End If
Call session.UpdateProcessedDoc( doc )
Set doc = unprocessedDocs.GetNextDocument(doc)
Loop
End Sub
Subject: You cannot use UI classes in agents that run on the server
so Dim uidoc As NotesUIDocument is no good
If you add error handling to your code, you would be able to see this more clearly.
So your problem lines are:
Dim uidoc As NotesUIDocument
Dim ws As New NotesUIWorkspace
Set uidoc = doc
Set rti = uidoc.document.getfirstitem(“memo”)
adoc.subject = uidocument.memoSubject(0)
You just want to use notesdocument.
Subject: Insert in Body field, not append…how?
Here is code we could live with, but I’d really prefer that the delivery failure details (OriginalSubject, etc.) are at the TOP of the Body field…so I want to insert, not append…
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim unprocessedDocs As NotesDocumentCollection
Dim doc As NotesDocument
Dim rti As NotesRichTextItem
Set db = session.CurrentDatabase
Set unprocessedDocs = db.UnprocessedDocuments
If unprocessedDocs.Count = 0 Then
Exit Sub
End If
Set doc = unprocessedDocs.GetFirstDocument()
Do While Not (doc Is Nothing)
If doc.form(0) Like "*NonDelivery Report*" Then
Call doc.PutInFolder( "Forwarded Delivery Failure" )
Set rti = doc.GetFirstItem("Body")
Call rti.AddNewLine( 1 )
Call rti.AddNewLine( 1 )
Call rti.AppendText("ORIGINAL SUBJECT: " & doc.subject(0))
Call rti.AddNewLine( 1 )
Call rti.AppendText("INTENDED RECIPIENT: " & doc.IntendedRecipient(0))
Call rti.AddNewLine( 1 )
Call rti.AppendText("FAILURE REASON: " & doc.FailureReason (0) )
doc.Subject = "Forwarded Delivery Failure= " & doc.FailureReason(0)
Call doc.Send( False, "MailboxA@xya.com")
Call doc.Removefromfolder("$Inbox")
End If
Call session.UpdateProcessedDoc( doc )
Set doc = unprocessedDocs.GetNextDocument(doc)
Loop
End Sub
Subject: So how do I mimic a manual forward?
Yes, debugger showed me those were the problem lines. Any ideas on how to get to where I want to go?
The situation is that another non-notes process reads mailbox A and if it is a delivery failure, it routes to mailbox B. My scheduled ‘when new mail arrives’ agent in Mailbox B wants to act JUST LIKE as if someone went into that Mailbox B and did a FOWARD back to mailboxA with a modified subject line. (I know this seems a bit curcular, but trust me, we need it)
So my code wants to:
-
Moves it from the INBOX of Mailbox B and put it in a new folder in Mailbox B…no problem.
-
Change the subject and foward it always to Mailbox A
If I use code that uses:
Call doc.Send( False, “MailboxA@xyz.com”)
the delivery failure information at the top of the document does not get sent along.
If I use code that says:
Set doc2 = doc.CopyToDatabase(db2)
the delivery failure info stays, but it is also form “NonDelivery Failure” instead of “Memo” (like when a FOWARD occurs). Therefore the original non-notes process repeatedly picks this up and we are going round and round. If I change the form to be ‘Memo’, then we again lose the delivery failure information. UGH
So, I know I can’t use ui statements in the scheduled agents. I really just want to mimic a foward to a pre-determined location.
Is the only thing to do is to strip off the OriginalSubject, IntendedRecipient and FailureReason and tack it to the Body field via the doc.send method?
Subject: RE: Add text field into the Body of an email … help!
Ok…but I’m looping through unprocessed documents in a scheduled agent…how do I get the NotesUIWorkspace to get the uidoc?
I feel this could be the answer, but need another nudge!
Subject: (preferably to the TOP of the body field)
Am I asking too much? I only see InsertText available for front end …