PDA

View Full Version : Search recipents and check attachment size combined



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

JP2112
08-06-2012, 07:28 AM
Use Instr to match on partials.

i.e.


If Instr(oMail.To, ".gov") > 0 Then

dro^
08-07-2012, 07:04 PM
Use Instr to match on partials.

i.e.


If Instr(oMail.To, ".gov") > 0 Then


It worked like a charm. Jp thanks for the fix but more importantly thanks for all the info you have posted on the net.:bow: I have been going over examples by you on your site and in forums you've solved and its been super helpful getting me off the ground. Going to start experimenting with this now to pull from a file but this is def the direction I needed. Thanks again - dro^

JP2112
08-08-2012, 06:52 AM
Thank you, you are too kind :thumb