Check Email Size Before Sending

Get a prompt if the size of an email exceeds a certain limit.

Last modified: 2006/01/18 | Accessed: 69.893  | #5
◀ Previous sample Next sample ▶
Category-Manager Category-Manager
With Category-Manager you can group your Outlook categories, share them with other users, filter a folder by category, automatically categorize new emails, and more. You can use the Addin even for IMAP.

This sample checks an e-mail's size before sending. You can cancel if it exceeds a pre-determined size. Here the limit is set to 10,000 bytes, which is a little less than 10kb. Adjust the value if needed.

tip  How to add macros to Outlook
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 = 10000 ' Byte
  Dim bSend As Boolean

  bSend = True
  If oMail.Attachments.Count Then
    lSize = oMail.Size
    If lSize > MAX_ITEM_SIZE Then
      bSend = (MsgBox("Item's size: " & lSize & " Byte. Cancel?", vbYesNo) = vbNo)
    End If
  End If
  ConfirmBigAttachments = bSend
End Function
ReplyAll ReplyAll
ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the e-mail.
email  Send a message