经发现,直接复制粘贴本文内容过去,导致双引号和单引号有问题,因此会有代码出错,建议粘贴过去前,先将”和’检查下,将lotus里粘贴过来的所有双引号和单引号用”和’替换一遍即可。否则会有红色字提示代码出错。
我在文末也附上txt档的文本,里面的双引号和单引号是对的。可以粘贴txt文档里的代码,点此下载1.。
1.
首先,新建一个Agent,其Runtime这里的属性选择为on event,after new mail has arrived。如下图。
2.
Declarations里,定义如下变量,
TargetEmail改成你自己需要转发的Email
Const TargetEmail = “XXX@xxx.com”
Dim db As notesdatabase
Dim session As NotesSession
3.
在Initialize那里,输入如下的代码:
Sub InitializeDim doc As NotesDocumentDim ReturnVal As BooleanDim PojistkaMax As IntegerDim collection As NotesDocumentCollectionDim Addeditem As NotesItemDim CurAgent As NotesAgentDim docStatus As VariantDim docProcessed As BooleanSet session = New NotesSessionSet db = session.CurrentDatabaseSet CurAgent = session.CurrentAgentPojistkaMax = 0Set collection = db.UnprocessedDocumentsSet doc = collection.GetFirstDocument()While Not(doc Is Nothing Or PojistkaMax>20)docStatus=””docProcessed = FalseIf (Doc.HasItem(CurAgent.Name & “_done”)) ThendocStatus = Doc.GetItemValue(CurAgent.Name & “_done”)If (Cstr(docStatus(0))=”1″) Then docProcessed=TrueEnd IfIf (docProcessed=False) ThenCall ProcessEmail (doc)If (Doc.HasItem(CurAgent.Name & “_done”)) ThenCall doc.ReplaceItemValue(CurAgent.Name & “_done”,”1″)Call doc.Save( True, False, False )ElseSet Addeditem = doc.AppendItemValue ( CurAgent.Name & “_done”, “1” )Call doc.Save( True, False, False )End IfEnd IfCall session.UpdateProcessedDoc(doc)Set doc = collection.GetNextDocument(doc)PojistkaMax = PojistkaMax + 1WendEnd SubSub ProcessEmail (Mydoc As NotesDocument)Dim rtnav As NotesRichTextNavigatorDim MyMssgHeader As StringDim rtitem As NotesRichTextItemDim Maildoc As NotesDocumentDim senderdomain As StringDim b As IntegerDim FromItem As NotesItemDim FromName As StringDim FromEmail As StringDim FromIDENT As StringDim FromOrig As StringDim ItemValue As VariantDim m_strForm As StringOn Error Goto GenErrorIf (MyDoc.IsEncrypted) Then Exit SubIf (myDoc.HasItem(“$KeepPrivate”)) ThenItemValue = MyDoc.GetItemValue(“$KeepPrivate”)If (Cstr(ItemValue(0))=”1″) Then Exit SubEnd IfIf (Not myDoc.HasItem(“From”)) Then Exit SubSet Maildoc = New NotesDocument(db)Call Mydoc.CopyAllItems( Maildoc, True )‘ If (Maildoc.HasEmbedded ) ThenSet rtitem = Maildoc.GetFirstItem(“Body”)‘ If ( rtitem.Type = RICHTEXT) Then‘ If (Not (Isempty(rtitem.EmbeddedObjects))) Then‘ Forall o In rtitem.EmbeddedObjects‘ If ( o.Type = EMBED_ATTACHMENT ) Then‘ Call o.Remove‘ End If‘ End Forall‘ End If‘ End If‘ End IfFromIDENT=””FromEmail=””FromName=””FromOrig=””If (MailDoc.HasItem(“Principal”)) ThenFromOrig=MailDoc.Principal(0)ElseFromOrig=MailDoc.From(0)End IfIf (Instr(1,FromOrig,”CN=”)>0 And Instr(1,FromOrig,”OU=”)>0) ThenFromIDENT=FromOrigElseCall ParseAddr (FromOrig,FromName, FromEmail)End If‘ add by JamesIf FromOrig =”Mail Router” ThenExit SubEnd IfIf FromOrig =”gcsecpoccoord” ThenExit SubEnd IfIf FromOrig =”LotusQuickr@USSECAVPQUCK02.na.ey.net” ThenExit SubEnd Ifm_strForm = MailDoc.GetItemValue ( “Form”)(0)If (Strcompare(m_strForm, “Delivery Report”) = 0) ThenExit SubEnd IfIf (Strcompare(m_strForm, “NonDelivery Report”) = 0) ThenExit SubEnd IfIf (Strcompare(m_strForm, “Trace Report”) = 0 ) ThenExit SubEnd IfIf (Strcompare(m_strForm, “Return Receipt”)= 0) ThenExit SubEnd If‘ end by JamesIf (FromIDENT<>””) ThenMailDoc.Principal = FromIDENTElseIf (FromEmail=””) ThenMailDoc.Principal = FromOrigElseMailDoc.Principal = FromName & ” <” & FromEmail & “@NotesDomain” & “>”MailDoc.INetFrom = FromName & ” <” & FromEmail & “>”End IfEnd IfIf (Mydoc.HasItem(“ReplyTo”)) ThenMaildoc.ReplyTo = Mydoc.ReplyTo(0)End Ifrtitem.AddNewline(2) ‘ add 2 new lines at the end of Bodyrtitem.AppendText(“In the Sent field was: “) ‘ add this text at the end of body, you can modify this part to add this only if in From field is allready somethingFor b=0 To Ubound(Maildoc.SendTo)rtitem.AppendText(Maildoc.SendTo(b) + “, “) ‘add all elements from From fieldNextrtitem.AddNewline(2) ‘ add 2 new lines at the end of Bodyrtitem.AppendText(“In the CC field was: “) ‘ add this text at the end of body, you can modify this part to add this only if in CC field is allready somethingFor b=0 To Ubound(Maildoc.CopyTo)rtitem.AppendText(Maildoc.CopyTo(b) + “, “) ‘add all elements from CC fieldNextrtitem.AddNewline(2) ‘ add 2 new lines at the end of Bodyrtitem.AppendText(“In the BCC field was: “) ‘ add this text at the end of body, you can modify this part to add this only if in CC field is allready somethingFor b=0 To Ubound(Maildoc.BlindCopyTo)rtitem.AppendText(Maildoc.BlindCopyTo(b) + “, “) ‘add all elements from CC fieldNextIf (Maildoc.HasItem(“CopyTo”)) ThenMaildoc.CopyTo = “”End IfIf (Maildoc.HasItem(“BlindCopyTo”)) ThenMaildoc.BlindCopyTo = “”End IfMaildoc.SendTo = TargetEmailCall Maildoc.Send(False)Set Maildoc = NothingExit SubGenError:Set Maildoc=NothingSet Maildoc = New NotesDocument(db)With Maildoc.Subject=”An error occured while parsing”.SendTo = TargetEmail.Body=”An error occured while parsing message ” & Mydoc.Subject(0) & “, from: ” & Mydoc.From(0) & “….Err msg: ” & Error$Call .Send(False)End WithSet Maildoc=NothingExit SubEnd SubSub ParseAddr (ParseWhat As String, Part1 As String,Part2 As String)Dim i As IntegerDim i2 As Integeri=Instr(1,ParseWhat,”<“)i2=Instr(i,ParseWhat,”>”)If (i>=i2) ThenExit SubEnd IfIf (i=0) Then i=0If (i2=0) Then i2=Len(ParseWhat)+1If (i>=3) ThenPart1=Mid(ParseWhat,1,i-2)End IfPart2=Mid(ParseWhat,i+1,i2-i-1)If (Instr(1,Part2,”@”)=0) ThenPart2=””End IfEnd Sub
之后,系统会自动帮你分割成如下的图:
4.
确认Terminate那边有如下的语句:
Sub TerminateEnd Sub
以上是通过Agent转发邮件的一个方法,已经考虑到了大部分的死循环问题,但不保证100%不会发生。本人编程水平有限。
以上资料供各位学习编程知识使用,请根据公司邮件要求/规则适当使用,本人不对使用上述代码所造成的损失负责。
Post writing is aso a fun, if yoou bbe familiar with afterward yoou ccan wrijte orr else it is complicated tto write.
Howdy! Do yoou use Twitter? I’d like tto follow you if tat wpuld bee okay.
I’m undoubtedly ennjoying youjr blog and lolok forward too neew
updates.
Quality rticles or reviews is tthe key too atttract tthe viwwers too go to
ssee thee website, that’s what tgis wweb page iis providing.
Hmmm is anyone ele encountering probles wijth thhe pictures on this bloog loading?
I’m tryng to find outt if its a problem onn
myy ennd or if it’sthe blog. Anny feed-back woukd be greatly appreciated.
Thanks , I’ve recently been loooking for info approximately ths toppic
ffor a lkng time and ylurs iis the bedst I’ve discoveded till now.
But, what concerning the bottom line? Arre you sure concerning the source?
There is ertainly a grsat deal to lean ablut this issue.
I like all thhe points you’ve made.
Hello there, jus became alert to our blog through Google, and found that it is really informative.
I’m gnna waatch outt for brussels. I’ll aplpreciate iff
you continue this in future. A lot oof peoplee will bee benefited from you writing.
Cheers!