vba - Outlook VBA 代码错误

标签 vba email outlook vsto

我有一个在 Outlook 2010 中的 Application_ItemSend 下运行的脚本。

它会检查收件人地址,如果它不是我们自己的域之一,则会提示一条确认消息,询问您是否要向外部发送电子邮件。

完整的代码可以在这里找到:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim recips As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim pa As Outlook.PropertyAccessor
Dim prompt As String
Dim strMsg As String

Const PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"

Set recips = Item.Recipients
For Each recip In recips
    Set pa = recip.PropertyAccessor
            If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@ourdomain1.com.au") = 0 And InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@ourdomain2.com.au") = 0 And InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@ourdomain3.com.au") = 0 And InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@ourdomain4.com.au") = 0 Then
    strMsg = strMsg & "   " & pa.GetProperty(PR_SMTP_ADDRESS) & vbNewLine
    End If
Next
For Each recip In recips
    Set pa = recip.PropertyAccessor
    If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@ourdomain1.com.au") = 0 And InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@ourdomain2.com.au") = 0 And InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@ourdomain3.com.au") = 0 And InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@ourdomain4.com.au") = 0 Then
    prompt = "This email will be sent outside of ourdomains.com.au to:" & vbNewLine & strMsg & "Do you want to proceed?"
    If MsgBox(prompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "Check Address") = vbNo Then
            Cancel = True
            Exit Sub
        Else
            Exit Sub
        End If
    End If
Next
End Sub

这非常有效,只是在发送到某些通讯组列表时它开始抛出错误。点击错误弹出窗口的“结束”,电子邮件仍会发送。

"The Property "http://schemas.microsoft.com/mapi/proptag/0x39FE001E" is unknown or cannot be found.

根据我的 google 搜索,这是因为并不总是存在 MIME 属性,因此它不能总是解析为 SMTP 地址。

我怎样才能改变这个,这样它就不会抛出错误?

最佳答案

该属性可能会也可能不会起作用,具体取决于收件人是否是您的 Exchange 组织内的 Exchange 用户,以及 Exchange 是否启用了缓存模式。

PR_SMTP_ADDRESS 在缓存模式下不可用。您可以在缓存模式下使用 PR_EMS_AB_PROXY_ADDRESSES,它是 PT_MV_STRING8 或 PT_MV_UNICODE(字符串数组)属性。

最后,您可能会找到 HowTo: Convert Exchange-based email address into SMTP email address文章有帮助。

关于vba - Outlook VBA 代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27497156/

相关文章:

javascript - 在 IOS 设备上填充快速类型栏选项

outlook - Outlook 中的 ICS 作为 .msg 文件发送

c# - 使用 C# 将公式写入现有 Excel 工作表的语法是什么?

excel - 如何找到Excel标记的单元格

Excel 2010 宏以突出显示事件单元格的行

excel - 选择整行数据

email - Safari 自动填充位置不正确

c# - smtp.live.com - 邮箱不可用。服务器响应为 : 5. 7.3 请求的操作已中止;用户未通过身份验证

excel - Outlook 电子邮件正文不会复制到 Excel

html - 电子邮件表格宽度在 Outlook 中中断