Outlook Automation - Change Sender Account

I am automating Outlook, and I need to control who the email comes from. Users will have two or more Accounts configured in Outlook, and I will need to choose which account to send email to. Any ideas?

Requires support in Outlook 2003 and above. I use Delphi 2006 to encode this, but that doesn't really matter.

+3
source share
2 answers

A man named Sue Mosher wrote a fairly brief overview of this problem in microsoft.public.office.developer.outlook.vba .

In short, it boils down to one of the following:

  • MailItem.SentOnBehalfOfName, Exchange ( , ) - " " Exchange, , .
  • , CommandBars
  • Outlook Redemption
  • ( OL2007 MailItem.SendUsingAccount)
+2

, Delphi Sue set_account. - , Delphi.

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;

, , :)

+2

Source: https://habr.com/ru/post/1698265/


All Articles