当我发送电子邮件(通过Outlook,所以我使用VBA)时,如果任何收件人地址的域不在域列表中,我想在主题行中添加“zsecure”。
这是我目前的代码:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim addrRecips As Outlook.Recipients
Dim addrRecip As Outlook.Recipient
Dim arrDomain As Variant
Dim pa As Outlook.PropertyAccessor
Dim recipDomain As String
Dim subjSecure As String
Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set addrRecips = Item.Recipients
' Set up the array
arrDomain = Array("domain1.com", "domain2.com", "domain3.com", "domain4.net")
For Each addrRecip In addrRecips
Set pa = addrRecip.PropertyAccessor
' Get the domain from the current recipient's email address
recipDomain = Split(pa.GetProperty(PR_SMTP_ADDRESS), "@", 2, vbTextCompare)(1)
Debug.Print recipDomain
' Check if the recipient's email domain is in the array of domains
If IsInArray(recipDomain, arrDomain) = False Then
Debug.Print "Recipient domain, " & recipDomain & ", is in array of domains"
' Current recipient's email domain is not in the list, so add " zsecure" to the subject
subjSecure = Item.Subject & " zsecure"
Item.Subject = subjSecure
' If any of the recipients' domains is not in the list, we can stop here and send the email
Exit Sub
End If
Next
End Sub
当我尝试发送电子邮件时,“IsInArray”会突出显示(选中),并且错误消息框显示“编译错误:Sub或Function not defined”。据我所知,我正在初始化,填充和使用数组,所以我没有看到导致错误的原因。
错误非常明确 - 函数IsInArray()
未在您的代码中定义,至少在您发布的代码段中没有定义。