Re: Size of Attachment before save



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

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook



> 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
>
> "Michael Bauer" wrote:
>
>> 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".
>>
>> --
>> Viele Gruesse / Best regards
>> Michael Bauer - MVP Outlook
>>
>>
>>
>>> 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
>>>
>>> "Michael Bauer" wrote:
>>>
>>>> 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.
>>>>
>>>> --
>>>> Viele Gruesse / Best regards
>>>> Michael Bauer - MVP Outlook
>>>>
>>>>
>>>>
>>>>> 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
>>>>
>>
.



Relevant Pages

  • Re: Possible to Disable Object Model Guard?
    ... Author of Microsoft Outlook 2007 Programming: ... Message.Configuration details for CDO. ... Dim OutMail As Object ... Dim cell As Range, FileCell As Range, rng As Range ...
    (microsoft.public.outlook.program_vba)
  • Re: Possible to Disable Object Model Guard?
    ... Message.Configuration details for CDO. ... I know almost nothing about programming Outlook. ... Dim OutMail As Object ... Dim cell As Range, FileCell As Range, rng As Range ...
    (microsoft.public.outlook.program_vba)
  • Re: CDO and Redemption Works in Outlook 2002 but crashes in Outlook 2000
    ... Are the users with Outlook 2000 using it in Internet only mode? ... the CDO Session.AddressBook and Redemption's MAPIUtils.AddressBook methods ... Dim m_redMapiUtils As Redemption.MAPIUtils ... Set redRecipients = Nothing ...
    (microsoft.public.exchange.development)
  • RE: Using cdo in MS Access VBA to automate email
    ... set a reference to the Outlook Object Library. ... Dim olApp As Object ... Set itmMail = olApp.CreateItem ... In the past I used cdo when I wanted to get an ACCOUNT,DISPLAY_NAME, ...
    (microsoft.public.access.modulesdaovba)
  • RE: Using cdo in MS Access VBA to automate email
    ... set a reference to the Outlook Object Library. ... Dim olApp As Object ... Set itmMail = olApp.CreateItem ... In the past I used cdo when I wanted to get an ACCOUNT,DISPLAY_NAME, ...
    (microsoft.public.access.modulesdaovba)