Expanding a bit on the accepted answer, I needed a Delphi implementation of Sue's set_account function. Couldn't find anything on the internet anywhere for this, so here is a Delphi interpretation of Sue's code.
Function SetAccount(TargetAccount:string; var MailItem:OLEVariant):boolean;
var OLI,CBs,CBP,MC:olevariant;
strAccountBtnName:String;
i,t:Integer;
FoundAccount:Boolean;
Const ID_ACCOUNTS = 31224;
begin
FoundAccount:=false;
OLI:=MailItem.GetInspector;
CBs:=OLI.CommandBars;
CBP:=CBs.FindControl(, ID_ACCOUNTS);
t:=1;
while (not FoundAccount) and (t<=CBP.Controls.Count) do begin
MC:=CBP.Controls[t];
i:=Pos(' ',MC.Caption);
if i > 0 Then strAccountBtnName:=Copy(MC.Caption,i+1,Length(MC.Caption)-i)
else strAccountBtnName:=MC.Caption;
if strAccountBtnName = TargetAccount then begin
MC.Execute;
FoundAccount:=true;
end;
inc(t);
end;
Result:=FoundAccount;
end;
Credit to Sue Mosher, thank you, couldn't have done it without you :)