Well, I blew it. I accidentally replied to an email that included people outside my company and attached a file with confidential data. It was a huge error, like giving away the nuclear codes.
So now that I still have a job, I'm looking to make sure that never happens again. I'm trying to create a VBA solution in Outlook that gives me a popup IF A) I'm sending to an outside doman and B) I'm including an attachment.
I found the following online here. It works well to alert me when I'm sending to an outside domain.
I think the code I need to check for attachments is:
However, when I put them together like this, I get an Object doesn’t support this property or method error.
Could anyone help me modify the code above to also check for attachments?
I appreciate any advice you can offer!
Thanks.
So now that I still have a job, I'm looking to make sure that never happens again. I'm trying to create a VBA solution in Outlook that gives me a popup IF A) I'm sending to an outside doman and B) I'm including an attachment.
I found the following online here. It works well to alert me when I'm sending to an outside domain.
Rich (BB code):
PrivateSub Application_ItemSend(ByVal Item AsObject, Cancel AsBoolean)Dim recips As Outlook.Recipients
Dim recip As Outlook.Recipient
Dim pa As Outlook.PropertyAccessor
Dim prompt AsString
Dim strMsg AsString
Const PR_SMTP_ADDRESS AsString="http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set recips = Item.Recipients
ForEach recip In recips
Set pa = recip.PropertyAccessor
If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)),"@example.com")=0Then
strMsg = strMsg &" "& pa.GetProperty(PR_SMTP_ADDRESS)& vbNewLine
EndIf
Next
If strMsg <>""Then
prompt ="This email will be sent outside of example.com to:"& vbNewLine & strMsg &"Do you want to proceed?"
If MsgBox(prompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground,"Check Address")= vbNo Then
Cancel =True
EndIf
EndIfEndSub
I think the code I need to check for attachments is:
Code:
Item.Attachements.Count > 0
However, when I put them together like this, I get an Object doesn’t support this property or method error.
Code:
If InStr(LCase(pa.GetProperty(PR_SMTP_ADDRESS)), "@example.com") = 0 And Item.Attachements.Count > 0 Then
Could anyone help me modify the code above to also check for attachments?
I appreciate any advice you can offer!
Thanks.
Last edited by a moderator: