如何检查您的Send TO短信ID是否在地址簿中有效

时间:2013-12-05 14:57:47

标签: lotus-notes lotusscript

    doc.Principal = confdoc.mDefaultPrincipal(0)
    doc.SendTo = curdoc.empShortID(0)

    Call doc.Send(False, False)

以上调用doc.Send(False,False)不会出现错误处理程序虽然doc.SendTo有错误的短ID,因为它有CC和BCC短ID是正确的。我的要求是它应该转到错误处理程序或它不应该发送邮件时发送错误。我如何检查发送到地址簿。

 errorhandler:
Print "Error in function TriggerMail -- " & Cstr(Error) &  " -- occured at line - " & Cstr(Erl())   
MsgBox Err

If Err = 4294 Then
    curdoc.Flag = "Invalid 'To' Shortname"
    curdoc.defaulterSLACount = CInt(defaultCount)
    Call curdoc.Save(False, True)
    Exit function
End If

1 个答案:

答案 0 :(得分:0)

不幸的是,只要至少有一个地址可以,就不会产生错误。 您必须手动检查所有地址以获取错误。最好的方法是遍历所有地址,然后查看($ Users) - 在domino目录中查看。 这可能如下所示:

Dim varRecipients as Variant
varRecipients = doc.SendTo
varRecipients = ArrayUnique( ArrayAppend( varRecipients, doc.CopyTo ) )
varRecipients = ArrayUnique( ArrayAppend( varRecipients, doc.BlindCopyTo ) )

Dim dbNab as NotesDatabase
Dim viwLkp as NotesView
Dim docPerson as NotesDocument
Set dbNab = New NotesDatabase( db.Server, "names.nsf" )
Set viwLkp = dbNab.GetView( "($Users)" )
Forall strRecipient in varRecipients
  '- this check is optional. Addresses with an @ never create an err 4294
  '- If your function never sends mails outside of the domain, you can omit it.
  If instr( strRecipient, "@" ) = 0 then
    Set docPerson = viwLkp.GetDocumentByKey( strRecipient, True )
    If docPerson is Nothing then
      '- flag your document, do whatever you want, 
      '- as this recipient does not exist
    End If
  End If
End Forall

此代码未经过测试,但该想法应该清晰,即使此示例中存在拼写错误(此时没有设计师打开来检查)。