Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Outlook自动化-更改发件人帐户_Outlook_Automation - Fatal编程技术网

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

Outlook自动化-更改发件人帐户,outlook,automation,Outlook,Automation,我正在自动化Outlook,我需要控制电子邮件似乎来自谁。用户将在Outlook中设置两个或多个帐户,我需要能够选择从哪个帐户发送电子邮件。有什么想法吗 需要Outlook 2003及以上版本的支持。我正在使用Delphi 2006来编写此代码,但这并不重要。一位名叫Sue Mosher的人在年写了一篇关于此问题的漂亮摘要 简言之,可以归结为以下两种情况之一: 使用MailItem.SentOnBehalfOfName,它只在Exchange环境中工作(我想您也是这样)-当用户对其他Excha

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


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

一位名叫Sue Mosher的人在年写了一篇关于此问题的漂亮摘要

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

  • 使用
    MailItem.SentOnBehalfOfName
    ,它只在Exchange环境中工作(我想您也是这样)-当用户对其他Exchange邮箱具有“发送为”权限时,这与切换帐户几乎是一样的
  • 使用一个小技巧,包括摆弄
    命令栏
  • 使用Outlook赎回
  • (在OL2007中,您将拥有
    MailItem.SendUsingAccount

我需要一个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;
函数SetAccount(TargetAccount:string;var-MailItem:OLEVariant):布尔值;
var-OLI、CBs、CBP、MC:油变异体;
strAccountBtnName:字符串;
i、 t:整数;
FoundAccount:布尔型;
Const ID_账户=31224;
开始
FoundAccount:=假;
OLI:=MailItem.GetInspector;
CBs:=OLI.commandbar;
CBP:=CBs.FindControl(,ID_账户);
t:=1;
while(不是FoundAccount)和(t0然后straccountbtname:=复制(MC.Caption,i+1,长度(MC.Caption)-i)
else straccountbtname:=MC.Caption;
如果strAccountBtnName=TargetAccount,则开始
执行;
FoundAccount:=真;
结束;
公司(t),;
结束;
结果:=FoundAccount;
结束;
Sue Mosher的功劳,谢谢你,没有你是不可能做到的:)