我正在自動化Outlook,我需要控制電子郵件的來源。用戶將在Outlook中設置兩個或更多帳戶,並且我需要能夠選擇從哪個帳戶發送電子郵件。有任何想法嗎?Outlook自動化 - 更改發件人帳戶
需要在Outlook 2003及更高版本上支持。我使用Delphi 2006來編寫代碼,但這並不重要。
我正在自動化Outlook,我需要控制電子郵件的來源。用戶將在Outlook中設置兩個或更多帳戶,並且我需要能夠選擇從哪個帳戶發送電子郵件。有任何想法嗎?Outlook自動化 - 更改發件人帳戶
需要在Outlook 2003及更高版本上支持。我使用Delphi 2006來編寫代碼,但這並不重要。
一個叫Sue Mosher的人在microsoft.public.office.developer.outlook.vba上寫了一篇關於這個問題的漂亮總結。
總之,歸結爲任一本:
MailItem.SentOnBehalfOfName
,其中僅在Exchange enviromnents工作(我想這是你的情況下) - 當用戶擁有「發送爲」權限對於其他Exchange郵箱,這與交換帳戶幾乎相同。CommandBars
MailItem.SendUsingAccount
)上公認的答案擴展了一下,我需要一個Delphi實現了Sue的set_account函數。因此無法在互聯網上找到任何東西,所以這裏是對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;
感謝薩·莫舍,謝謝你,不能做它沒有你:)
@Kiquenet你是超過歡迎提供一個。 :) – Tomalak 2013-04-23 08:21:23