当我发送电子邮件(通过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“被高亮显示(选中),错误消息框显示”编译错误:子函数未定义“。据我所知,我正在正确地初始化、填充和使用数组,所以我看不到是什么导致了错误。
发布于 2019-02-22 06:12:21
错误非常明确-函数IsInArray()
没有在您的代码中定义,至少在您发布的代码片段中没有定义。
https://stackoverflow.com/questions/54816666
复制相似问题