avoid deleting attachments in outlook using addin programming - outlook-addin

I wonder if there is any way to avoid deleting attachments in outlook mailItem using code
either with right clicking and select remove or delete by pressing delete key.
I didn't find any solution like [beforeAttachment] event for it.

Removing attachments is only committed if the MailItem is then saved. Therefore one thing you could do is add an event handler for the AttachmentRemove event, and set a flag if the event fires. Armed with the knowledge that an attachment has been removed, you could then deny attempts to save the MailItem, by cancelling the Write event or by whatever means works best with your code.

Related

How can I automatically flag an email after reply in Outlook

I would like to see if there is any way that anyone replies in a shared mailbox to any email and the email is automatically flagged in outlook. Can be via Power Automate or VBA.
One way or another, you would need to set the MailItem.Categories property and/or MailItem.ReminderSet / ReminderTime properties on the original item in the folder.
You can use Explorer.SelectionChange event to track the item selection, set up MailItem.Reply/ReplyAll event handlers on the item(s) from the Explorer.Selection collection, and then set the reminder properties in the event handler. Or you can use Explorer.InlineResponse event to set up the properties on the first item in the Explorer.Selection collection

VSTO Outlook AddIn: How to handle event when AppointmentItem.Body changes

I tried to catch the event when the AppointmentItem.Body changes. Handling the PropertyChange on the AppointmentItem does not get called when I type in text or save the AppointmentItem. It gets called when I hit the button "Add Participants though".
Best would be to get the Keydown on the body editor?
The Outlook object model may not propagate changes made in the Outlook UI until you switch focus to another field and/or save the item. This is a well-known issue when dealing with the Outlook object model.

Outlook VSTO-AddIn: Prevent Outlook from deleting an appointment

I try to prohibit in certain cases that the user deletes an appointment. Something like this:
User clicks on appointment in calendar
User selects delete
VSTO-Addin checks whether this is allowed and shows a warning dialog in case if not. Outlook does NOT delete the appointment!
Currently I attached to Item_Delete_Add() and I think that one can only handle the deletion but you cannot prevent outlook from actually deleting the appointment. Correct?
You are on the right avenue... The Items.ItemRemove event is fired when an item is deleted from the specified collection. This event does not run when the last item in a Personal Folders file (.pst) is deleted, or if 16 or more items are deleted at once from a PST file, Microsoft Exchange mailbox, or an Exchange public folder. Moreover, you must keep the reference to the source object to know which item is being deleted from a folder. To get this working you must subscribe to the SelectionChange event of the Explorer class. It is fired when the user selects a different or additional Microsoft Outlook item programmatically or by interacting with the user interface. So, you could subscribe to every selected item and know which item exactly is removed.
Another possible way is to handle the AppointmentItem.BeforeDelete event which is fired before an item (which is an instance of the parent object) is deleted. An instance of the item being deleted is passed as a parameter. In order for this event to fire when an email message, distribution list, journal entry, task, contact, or post are deleted through an action, an inspector must be open. The event occurs each time an item is deleted. It also allows to cancel the actions by setting the second parameter - if the event procedure sets this argument to true, the operation is not completed and the item is not deleted.
Yet another approach is to repurpose ribbon controls, see Temporarily Repurpose Commands on the Office Fluent Ribbon for more information.

How can the Add.Item event works at Outlook opening?

I got an issue with the macro I did in Outlook. To resume, the macro starts every time I receive an email. Then it will run a few others Sub, modify an Excel file and so one. When Outlook is running and I receive a new email, everything works perfectly. The problem occurs when I open Outlook and I receive more than one email at the same time.
I suppose the macro doesn't have enough time to end what it's doing with the first email and already try to start again with the next one.
Is there a way to keep the next emails in suspend in order to run the macro for each email, each one has its turn ? Or maybe you have another solution ?
Thank you.
PS: I can provide the code but it's very long.
The problem occurs when I open Outlook and I receive more than one email at the same time.
The NewMailEx event of the Application class is fired once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item.
The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item.
Make sure VBA macros are enabled and allowed to run when Outlook is started. Check out the Trust Center settings in Outlook.

Create Msg Read View Outlook

I'm writing an Outlook Addin Ribbon in VB.net and getting on with it rather well, however I've come to a point where I'm stuck.
When sending an item, I also need to save the file in the reading format which it would appear in the 'Sent Items'.
If have tried mailItem.SaveAs("path", olSaveAsType) but it only saves as a draft item. Whereby you can edit the text.
I tried to loop through the sent items in the 'sent items' folder after sending, however Outlook hangs whilst my code is executing, thus holding up the actual sending of the email.
Is there a way this can be done?
Any help, hints or tips would be appreciated!
Message submission is an asynchronous process. Set up the Items.ItemAdd event handler on the Sent Items folder (Namespace.GetDefaultFolder(olFolderSentMail)) and process the sent message in the ItemAdd event handler.