Home > OS >  Is there a way I can programmatically attach a large file to an outlook message despite it exceeding
Is there a way I can programmatically attach a large file to an outlook message despite it exceeding

Time:02-12

I am hoping there is something I can do here to ensure that attaching a large file to an Outlook.MailItem works exactly the same as doing so manually.

To be precise... when a user composes an email in Outlook and they attach a file that is too large to the email, Outlook will happily attach the file to the email. Instead of simply refusing to do so, it will attach the file and a message will appear in the Inspector: Composing a message and adding an attachment that is way too big

However....

When coding a similar action you would get access to an Outlook.MailItem and you would invoke the .Add method on its .Attachments object

oMailObject.Attachments.Add("<path to a file that is way too big here>")

The problem is that that action fails. An error is thrown "The file you're attaching is bigger than the server allows. Try putting the file in a shared location and sending a link instead."

Yes, we can obviously catch the error and then show a message to the user. That's what we're currently doing. It would, however, be nicer if there were a way I can prevent it from raising the error so it would still attach the file to the MailItem, and then when I show the inspector to the user they would see the same thing they would see if they had attached the attachment manually.

Is there an option on the MailItem to prevent it raising an error? Something in the Attachments.Add method? Any suggestions?

CodePudding user response:

The Attachments.Add method doesn't provide anything for that.

You may consider adjusting the maximum size of the attachments in Outlook. Regular mail profiles can be configured using the windows registry keys.

HKEY_CURRENT_USER\Software\Microsoft\Office\<x.0>\Outlook\Preferences
HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\ x.0 \Outlook\Preferences

There you can add a value type: DWORD Value name: MaximumAttachmentSize Value data: An integer that specifies the total maximum allowable attachment size. For example, specify 30720 (Decimal) to configure a 30-MB limit. Specify a value of zero (0) if you want to configure no limit for attachments.

Exchange accounts require configuration on the Exchange side, read more about that in the Microsoft Exchange Server email account configuration section.

CodePudding user response:

You can read PR_MAX_SUBMIT_MESSAGE_SIZE MAPI property (DASL name is "http://schemas.microsoft.com/mapi/proptag/0x666D0003") from the store (use Store.PropertyAccessor.GetProperty) - it returns the size in kB - prior to sending the message. This property is Exchange-specific.

  • Related