代码之家  ›  专栏  ›  技术社区  ›  AviD

Outlook自动化-更改发件人帐户

  •  3
  • AviD  · 技术社区  · 16 年前

    我正在自动化Outlook,我需要控制电子邮件似乎来自谁。用户将在Outlook中设置两个或多个帐户,我需要能够选择从哪个帐户发送电子邮件。有什么想法吗?

    需要Outlook 2003及以上版本的支持。我使用Delphi2006来编写这个代码,但这并不重要。

    2 回复  |  直到 16 年前
        1
  •  2
  •   Tomalak    16 年前

    一个叫苏·莫舍的人在《纽约时报》上写了一篇关于这个问题的摘要 microsoft.public.office.developer.outlook.vba .

    简言之,可以归结为以下两种情况之一:

    • 使用 MailItem.SentOnBehalfOfName ,它只在Exchange环境中工作(我想您就是这样)-当用户对另一个Exchange邮箱具有“发送为”权限时,这与切换帐户几乎是一样的。
    • 使用一个小技巧,包括摆弄 CommandBars
    • 使用Outlook赎回
    • MailItem.SendUsingAccount )
        2
  •  2
  •   Tim Post Samir J M Araujo    13 年前

    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;
    

    Sue Mosher的功劳,谢谢你,没有你是不可能做到的:)