Outlook) (MailItem.Sender 屬性

會傳回或設定 AddressEntry 物件,這個物件對應至傳送 MailItem 的帳戶使用者。 讀取/寫入。

語法

expressionSender

表達 代表 MailItem 物件的 變數。

註解

您可以在已於設定檔中定義多個帳戶的工作階段中設定此屬性,以指定要用來傳送郵件項目的帳戶。 將此屬性設定為特定帳戶之CurrentUser屬性所代表之使用者的AddressEntry物件。

如果您將 Sender 屬性設定為沒有許可權在該帳戶上傳送郵件的 AddressEntry ,Microsoft Outlook 將會引發錯誤。

範例

Michael Bauer 提供下列程式碼範例。 Michael 是 Microsoft 最有價值專家 ,具備在 Visual Basic 和 Visual Basic for Applications (VBA) 中開發 Outlook 解決方案的專業知識。 Michael 在 VBOffice.net維護專業網站。

下列 VBA 程式碼範例示範如何顯示電子郵件寄件者詳細資料。 如果寄件者對應至使用者 Outlook 連絡人通訊錄 (CAB) 中的連絡人,程式碼範例會在偵測器中顯示該連絡人的相關資訊。 如果寄件者不是使用者 CAB 中的連絡人,程式碼範例會顯示使用者位址專案的詳細資料, (取自傳輸提供者的通訊錄容器,) 對話方塊中。

若要顯示寄件者的資訊,使用者應該已在總管中選取 MailItem 。 程式碼範例也會檢查是否已傳送選取的MailItem,因為只有在已傳送Mailtem時,才會定義Sender屬性。 然後,此範例會存取 Sender 屬性,以取得對應至該訊息項目之寄件者的 AddressEntry 物件,並在該訊息項目存在時顯示連絡人資訊;否則,此範例會顯示位址專案詳細資料。

 
Public Sub DisplaySenderDetails() 
 Dim Explorer As Outlook.Explorer 
 Dim CurrentItem As Object 
 Dim Sender As Outlook.AddressEntry 
 Dim Contact As Outlook.ContactItem 
 
 Set Explorer = Application.ActiveExplorer 
 
 ' Check whether any item is selected in the current folder. 
 If Explorer.Selection.Count Then 
 
 ' Get the first selected item. 
 Set CurrentItem = Explorer.Selection(1) 
 
 ' Check for the type of the selected item as only the 
 ' MailItem object has the Sender property. 
 If CurrentItem.Class = olMail Then 
 Set Sender = CurrentItem.Sender 
 
 ' There is no sender if the item has not been sent yet. 
 If Sender Is Nothing Then 
 MsgBox "There's no sender for the current email", vbInformation 
 Exit Sub 
 End If 
 
 Set Contact = Sender.GetContact 
 
 If Not Contact Is Nothing Then 
 ' The sender is stored in the contacts folder, 
 ' so the contact item can be displayed. 
 Contact.Display 
 
 Else 
 ' If the contact cannot be found, display the 
 ' address entry in the properties dialog box. 
 Sender.Details 0 
 End If 
 End If 
 End If 
End Sub

另請參閱

MailItem 物件

操作方法:根據目前資料夾建立特定帳戶的可傳送項目

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應