Check outlook account on sending message

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

Check outlook account on sending message
 
bluewwol




Posts: 26
Joined: 2022-01-21
I have the function below that works just fine when the Item is a new message however when it is a reply or a forward it generates an exception on the instruction:
Inspector.CurrentItem.QueryInterface(IID__MailItem, IMail);

This function is called from the adxCOMAddInModuleSendMessage event with the same parameters.

As always any thoughts or pointers would be welcome.

-Allen


function TAddInModule.TestAccountActive(ASender: TObject; const Item: IDispatch; var Cancel: WordBool): Boolean;
var
  ol2010: Outlook2010._Application;
  i, J: Integer;
  IMail: Outlook2010._MailItem;
  Inspector: Outlook2000._Inspector;
begin
  IMail := (Item as Outlook2010._MailItem);
  Inspector := OutlookApp.ActiveInspector;
  Result := False;
  try
    try
      Inspector.CurrentItem.QueryInterface(IID__MailItem, IMail);     // <<< exception raised here.
      ol2010 := Self.OutlookApp.Application as Outlook2010._Application;
      for i := 1 to ol2010.Session.Accounts.Count do
      begin
        // objAccount:= IMail.SendUsingAccount;
        if (IMail.SendUsingAccount.DisplayName = ol2010.Session.Accounts.Item(i).DisplayName) then
        begin
          for J := 0 to Length(dMain.AccountsArray) - 1 do
          begin
            if dMain.AccountsArray[J].AccntName = ol2010.Session.Accounts.Item(i).DisplayName then
            begin
              Result := dMain.AccountsArray[J].Enabled;
              Exit;
            end;
          end;
        end;
      end;
    except
      // This is a problem....
      Result := true;
    end;
  finally
    IMail := nil;
  end;
end;
Posted 23 Jan, 2022 18:29:39 Top
Andrei Smolin


Add-in Express team


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

I assume it the function is called on the main thread.

If so, try to restart the machine. If that doesn't help, try to repair Office. Then you can try to reinstall it.

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 24 Jan, 2022 03:48:06 Top
bluewwol




Posts: 26
Joined: 2022-01-21
Andrei Smolin writes:
If so, try to restart the machine. If that doesn't help, try to repair Office. Then you can try to reinstall it.


Thanks Andre, I did the following, Uninstall my add-in, reboot machine, Repair Outlook, Reinstall my add-in, and the error persists.

And Yes this is being run without introducing new threads. The function is called directly from the OnSendMessage event, and is passing the parameters unmodified to my function.

Any further suggestions welcome.

-Allen
Posted 24 Jan, 2022 14:44:42 Top
bluewwol




Posts: 26
Joined: 2022-01-21
Is my add-in TLB correct, I added nothing to what was generated by the new project wizard, however when reviewing other of your samples it appears I may be missing something. I apologize for the clueless question as this is my very first add-in and what seems very simple is eluding me.
my TLB unit

unit wwolAddIn_TLB;

{$TYPEDADDRESS OFF}                          // Unit must be compiled without type-checked pointers.
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}


interface

uses SysUtils, ComObj, ComServ, ActiveX, Variants;

const
  // TypeLibrary Major and minor versions
  wwolAddInMajorVersion = 1;
  wwolAddInMinorVersion = 0;

  LIBID_wwolAddIn: TGUID = '{E1414801-9189-442A-AD37-B0C3462A733F}';   

  IID_IwwolOUT: TGUID = '{C31287BF-E9A2-4DCB-AE23-14A3A53BC78A}';      
  CLASS_wwolOUT: TGUID = '{208A767B-87DD-475D-B68C-66183F32D183}';     

type
  IwwolOUT = interface(IDispatch)
    ['{C31287BF-E9A2-4DCB-AE23-14A3A53BC78A}']
  end;

  IwwolOUTDisp = dispinterface
    ['{C31287BF-E9A2-4DCB-AE23-14A3A53BC78A}']
  end;

implementation

end.
Posted 24 Jan, 2022 21:05:18 Top
Andrei Smolin


Add-in Express team


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

Could you please send us a project reproducing the issue to our support email address? Find it in {Add-in Express installation folder}\readme.txt; please make sure your email contains a link to this topic.

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Jan, 2022 06:43:05 Top
bluewwol




Posts: 26
Joined: 2022-01-21
Andrei Smolin writes:
Could you please send us a project reproducing the issue to our support email address?

Andrei;

I had some issues emailing you last night did you receive my project?

-Allen
Posted 26 Jan, 2022 13:31:19 Top
Andrei Smolin


Add-in Express team


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

We can't compile your project as we do not have uUtils, uAppSettings, jclStrings, mapi, mapidefs and some other units.

You call TestAccountActive from the ItemSend event. That event already have the item being sent. Accordingly, you do not need to call ActiveInspector.CurrentItem.

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Jan, 2022 04:01:16 Top
Andrei Smolin


Add-in Express team


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

The project you've sent us still gets the item via ActiveInspector.CurrentItem. While it needs to use the item passed to the event procedure through the event parameters.

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 31 Jan, 2022 04:09:03 Top
bluewwol




Posts: 26
Joined: 2022-01-21
Andrei Smolin writes:
The project you've sent us still gets the item via ActiveInspector.CurrentItem. While it needs to use the item passed to the event procedure through the event parameters.


Andrei;

I do get the item when the message is a new message, however when it is a forward or a reply it throws an exception.
Posted 31 Jan, 2022 10:10:22 Top
Andrei Smolin


Add-in Express team


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

Are you saying that sending a forwarded item causes your code to fail when it invokes {the item being sent}.QueryInterface(IID__MailItem, IMail)?

Regards from Poland (CET),

Andrei Smolin
Add-in Express Team Leader
Posted 31 Jan, 2022 10:21:51 Top