Size of Attachment before save

G

Guest

I've searched the Outlook object model for at least a day. I am trying to
write code that will test the size of a file attachment BEFORE the user saves
to the Exchange DB. I've found the BeforeAttachmentSave event, and the
Attachment property of the MailItem. There's also the Size property of the
Mailitem. Unfortunately the attachment must be saved before the Size
property reflects the total size of the Item (message & attachment.). I've
tried to use the FileSystem but the Attachment PathName property doesn't
contain the path to the file (documented and tested).

GOAL: The goal of this small program is to alert and stop a user in the
attempt to attach a large file (> 100 mb for example) before they save or
send. I don't have the overhead in the Exchange DB to allow users to try. I
have the usual policies set for Send and Receive, unfortunately this doesn't
stop the users from trying, which overloads the DB capacity.

Any ideas on another approach would be appreciated.
Kevin
 
M

Michael Bauer

Am Tue, 29 Nov 2005 08:55:33 -0800 schrieb Kevin Kutzera:

Kevin, you can use CDO (optional component from the Office CD) to read the
CdoPR_ATTACH_SIZE field.

Or simply use the Redemption (www.dimastr.com). Its Attachment object has a
Size property.
 
G

Guest

Michael,
Thanks for the response. I've located the cdo.dll on my Exchange Server.
It only contains a const CdoPR_ATTACH_SIZE set to some big number. I'm
guessing I have the wrong library.
I've search both the Office 2003 standard and Professional CD's. During
maintenance install of both products there are no optional components
(everything is either installed or install at first use). I can not find
the correct library anywhere. I'd appreciate any further direction you can
provide.
MSCN article 171440 dicusses finding CDO libraries. I does not indicate
that the Office install will provide the CDO library, but the Outlook install
will. I'll keep looking.
Thanks
Kevin
 
M

Michael Bauer

Am Fri, 2 Dec 2005 11:30:03 -0800 schrieb Kevin Kutzera:

It´s the Outlook installation, correct. For most people this can be found on
the Office CD.

First I´d look in the VBA project if CDO is installed already. Please open
the project and click Tools/References, search for "Microsoft CDO 1.21
Library". If there´s no such item then install it from your CD where it´s
called something like "Collaboration Data Objects".
 
G

Guest

Michael,

Thanks for the follow-up. Been a few days since I could turn my attention
to this again.

Found the CDO. I have it installed. The CdoPR_ATTACH_SIZE is a constant
read only. Still not sure how to get the size of the attachment before the
user actually saves it to the message, and thus the Exchange DB.

I suspect the constant is used as a parameter in another function that servs
to retrieve properties of the attachment. Can't find any documentation to
that effect.

Another thing I noticed which might defeat the purpose of this utility is
that Outlook automatically saves to the Draft without user action (like
during the attachment process if the user delays in acknowledging a prompt).
So the mailitem is saved with the attachment unless I cancel it in the
BeforeAttachmentSave event.

If you have any more info for me I'd greatly appreciate it.

Kevin
 
M

Michael Bauer

Am Fri, 9 Dec 2005 14:56:02 -0800 schrieb Kevin Kutzera:

Kevin, the following sample is for CDO and it´s necessary that an e-mail is
saved before it can be casted to a CDO Message.

Private Sub m_oMail_AttachmentAdd(ByVal Attachment As Outlook.Attachment)
Dim oMsg As MAPI.Message
Dim oAtt As MAPI.Attachment
Dim lSize As Long

If m_oMail.Saved = False Then
m_oMail.Save
End If
Set oMsg = GetMessage(m_oMail)
Set oAtt = oMsg.Attachments(Attachment.Index)
lSize = oAtt.Fields(CdoPR_ATTACH_SIZE)
If lSize > 1000 Then
MsgBox "att too big"
Attachment.Delete
End If
End Sub

Public Function GetMessage(oObj As Object, Optional oSess As MAPI.Session)
As MAPI.Message
On Error Resume Next
Dim sEntryID As String
Dim sStoreID As String

sEntryID = oObj.EntryID
sStoreID = oObj.Parent.StoreID
If oSess Is Nothing Then
Set oSess = CreateObject("MAPI.Session")
oSess.LogOn , , False, False, , True
End If
Set GetMessage = oSess.GetMessage(sEntryID, sStoreID)
End Function
 
G

Guest

Thanks!
Since the e-mail has to be saved before the size test, it defeats the
purpose of the program I'm trying to create. Fortunately SP 2 of Exchange
Server increases the limit of the Standard edition DB to 75GB. This means I
don't have to run the system so close to the limit. Using individual account
policies and diligent database monitoring should keep us out of trouble in
the future.
Really appreciate your time on this.
Regards
Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top