dro^
08-01-2012, 07:04 AM
Hello folks,
I am trying to get outlook to check 2 things before sending emails. 1) Is this going to a .gov (or other specified domain) 2) Is it over 5mb. If so prompt msg box with error and a cancel or continue box.
Did my normal google found some code that checks the attachment size well then added a line to it to check the "To" section, which it does as well. My problem is that it only works with full email address if I try to "*.gov ",".gov" or something similar it doesn't work. Could someone please point me in the right direction?
Regards,
dro^
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeOf Item Is Outlook.MailItem Then
Cancel = Not (ConfirmBigAttachments(Item))
End If
End Sub
Private Function ConfirmBigAttachments(oMail As Outlook.MailItem) As Boolean
Dim lSize As Long
Const MAX_ITEM_SIZE As Long = 5120 ' Byte
Dim bSend As Boolean
bSend = True
If oMail.To = "whatever@whatever.com" Then
If oMail.Attachments.Count Then
oMail.Save
lSize = oMail.Size
If lSize > MAX_ITEM_SIZE Then
bSend = (MsgBox("Item's size exceeds 5MB: " & lSize & " Byte. Cancel?", vbYesNo) = vbNo)
End If
End If
End If
ConfirmBigAttachments = bSend
End Function
I am trying to get outlook to check 2 things before sending emails. 1) Is this going to a .gov (or other specified domain) 2) Is it over 5mb. If so prompt msg box with error and a cancel or continue box.
Did my normal google found some code that checks the attachment size well then added a line to it to check the "To" section, which it does as well. My problem is that it only works with full email address if I try to "*.gov ",".gov" or something similar it doesn't work. Could someone please point me in the right direction?
Regards,
dro^
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeOf Item Is Outlook.MailItem Then
Cancel = Not (ConfirmBigAttachments(Item))
End If
End Sub
Private Function ConfirmBigAttachments(oMail As Outlook.MailItem) As Boolean
Dim lSize As Long
Const MAX_ITEM_SIZE As Long = 5120 ' Byte
Dim bSend As Boolean
bSend = True
If oMail.To = "whatever@whatever.com" Then
If oMail.Attachments.Count Then
oMail.Save
lSize = oMail.Size
If lSize > MAX_ITEM_SIZE Then
bSend = (MsgBox("Item's size exceeds 5MB: " & lSize & " Byte. Cancel?", vbYesNo) = vbNo)
End If
End If
End If
ConfirmBigAttachments = bSend
End Function