【问题标题】:Outlook automation - Change Sender AccountOutlook 自动化 - 更改发件人帐户
【发布时间】:2010-09-17 03:23:53
【问题描述】:

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

需要 Outlook 2003 及更高版本支持。我正在使用 Delphi 2006 来编写代码,但这并不重要。

【问题讨论】:

    标签: outlook automation


    【解决方案1】:

    一个名叫 Sue Mosher 的人在 microsoft.public.office.developer.outlook.vba 上写了一篇关于这个问题的漂亮总结。

    简而言之,它归结为以下任何一种:

    • 使用MailItem.SentOnBehalfOfName,它仅适用于 Exchange 环境(我想您就是这种情况) - 当用户对另一个 Exchange 邮箱具有“发送为”权限时,这与切换帐户几乎相同.
    • 使用涉及摆弄CommandBars 的小技巧
    • 使用 Outlook 兑换
    • (在 OL2007 中,您将拥有 MailItem.SendUsingAccount
    【解决方案2】:

    扩展一点已接受的答案,我需要 Sue 的 set_account 函数的 Delphi 实现。在互联网上的任何地方都找不到任何东西,所以这里是对 Sue 代码的 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;
    

    感谢 Sue Mosher,谢谢你,没有你我做不到 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-04
      相关资源
      最近更新 更多