Outlook AfterSend

Add-in Express™ Support Service
That's what is more important than anything else

Outlook AfterSend
work with message after outlook has completed the send operation 
bluewwol




Posts: 26
Joined: 2022-01-21
Hi,

I am wanting to work on a message after Outlook has completed the send operation, I am unable to locate an event that allows this, does anyone have any advice or insights on how to achieve this?

Thanks for any assistance

-Allen
Posted 15 Nov, 2022 09:21:52 Top
Andrei Smolin


Add-in Express team


Posts: 18993
Joined: 2006-05-11
Hello Allen,

Put an ADXOutlookAppEvents component onto the add-in module. Select the component. In the Properties window expand the HandleEvents property and set SyncObjects to true. Then handle SyncStart, SyncEnd, SyncError, and SyncProgress events that the component provides. Note that the issue described in https://social.msdn.microsoft.com/Forums/office/en-US/7a20664c-7650-4d61-9d5f-13f1d929a8cd/outlook-2013-automatic-sendreceive-doesnt-work-with-the-sample-addin-below?forum=outlookdev may still persist in modern Outlook versions despite the last post in that thread.

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 15 Nov, 2022 09:47:13 Top
bluewwol




Posts: 26
Joined: 2022-01-21
Hi Andrei;

I noticed that the Sync Events are quite delayed. After sleuthing around I arrived at this solution which is working quite well.
For each account set in Outlook I execute this code to setup the events

            objStore := ol2010.Session.Accounts.Item(i).DeliveryStore;
            IFolderSent := objStore.GetDefaultFolder(olFolderSentMail);

            if Assigned(IFolderSent) then
              try
                dMain.AccountsArray[i - 1].FItems := TItems.Create(nil);
                dMain.AccountsArray[i - 1].FItems.ConnectTo(Outlook2000._Items(IFolderSent.Items));
                dMain.AccountsArray[i - 1].FItems.OnItemAdd := DoItemChange;
              finally
                IFolderSent := nil;
              end;


However I notice that my AddInFinalize code is never executed, or at least the break points into the code are never triggered. There is no exception generated and Outlook seems to have terminated normally?? Any suggestions?


procedure TAddInModule.adxCOMAddInModuleAddInFinalize(Sender: TObject);
var
  i: Integer;
begin

  if dMain <> nil then
  begin
    for i := 0 to Length(dMain.AccountsArray) - 1 do
      dMain.AccountsArray[i].FItems.Free;

    dMain.Free;
  end;
  OutlookApp.OnItemSend := nil;
  if Assigned(FItems) then
    FreeAndNil(FItems);
end;


-Allen
Posted 17 Nov, 2022 11:23:35 Top
Andrei Smolin


Add-in Express team


Posts: 18993
Joined: 2006-05-11
Hello Allen,

1. It is possible to send an email without creating a copy in the Sent Items folder. You can do this programmatically- set theMailitem.SaveSentMessageFolder := nil. There?Â?Ð?és an UI option, too; I can?Â?Ð?é point you to that option at the moment, sorry. You can?Â?Ð?ét get the *current* state of that UI option; you can only find what it?Â?Ð?és value was when Outlook started.

2. This is the default behaviour of Outlook; see e.g. https://www.add-in-express.com/creating-addins-blog/2010/05/04/outlook2010-fast-shutdown/

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 21 Nov, 2022 04:57:17 Top
bluewwol




Posts: 26
Joined: 2022-01-21
Andrei;

Thank you, this did solve my finalize problem.


procedure TAddInModule.adxOutlookAppEvents1Quit(Sender: TObject);
begin
  if Self.OutlookShutdownBehavior = osFast then
  begin
    adxCOMAddInModuleAddInFinalize(Sender);
  end;
end;
Posted 21 Nov, 2022 11:50:34 Top
Andrei Smolin


Add-in Express team


Posts: 18993
Joined: 2006-05-11
You are welcome!

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 21 Nov, 2022 11:56:18 Top