Outlook VBA error

I have a script that runs under Application_ItemSend in Outlook 2010.

It verifies the recipient's address, and if it is not one of our own domains, it prompts for confirmation if you want to send an email from outside.

The complete code for this can be found here:

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

      

This works great, except that there was an error submitting to some mailing lists. Clicking "end" on the popup error message is still sent.

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

From what I have google'd, this is because the MIME property is not always present, so it cannot always be resolved to the SMTP address.

How can I change this so that it doesn't throw an error?

+3


source to share


2 answers


This property may or may not work, depending on whether the recipient is an Exchange user in the Exchange organization and whether Cached Mode is enabled in Exchange.

PR_SMTP_ADDRESS is not available in cached mode. You have to use PR_EMS_AB_PROXY_ADDRESSES in cached mode, which is PT_MV_STRING8 or PT_MV_UNICODE (string array) property.



Finally, you can find HowTo: Convert Exchange Based Email Address to SMTP Email Address .

0


source


PR_SMTP_ADDRESS is not guaranteed. Also, if you are sending SMTP to the recipient, the property will not be present, but the PR_EMAIL_ADDRESSS property (displayed by the Recipient.Address property) will contain the normal SMTP address.



Check if PR_ADDRTYPE is "SMTP" and read PR_EMAIL_ADDRESSS. Otherwise, try (and handle the error appropriately) to read the PR_SMTP_ADDRESS property.

0


source







All Articles