MailAddress.DisplayName 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得顯示名稱,該名稱是由建立這個執行個體時所指定的顯示名稱和地址資訊所組成。
public:
property System::String ^ DisplayName { System::String ^ get(); };
public string DisplayName { get; }
member this.DisplayName : string
Public ReadOnly Property DisplayName As String
屬性值
包含顯示名稱的 String,但如果在建立這個執行個體時沒有指定顯示名稱資訊,則為 Empty ("")。
範例
下列程式代碼範例會顯示 DisplayName 電子郵件訊息收件者的 。
static void CreateBccTestMessage( String^ server )
{
MailAddress^ from = gcnew MailAddress( L"ben@contoso.com",L"Ben Miller" );
MailAddress^ to = gcnew MailAddress( L"jane@contoso.com",L"Jane Clayton" );
MailMessage^ message = gcnew MailMessage( from,to );
message->Subject = L"Using the SmtpClient class.";
message->Body = L"Using this feature, you can send an email message from an application very easily.";
MailAddress^ bcc = gcnew MailAddress( L"manager1@contoso.com" );
message->Bcc->Add( bcc );
SmtpClient^ client = gcnew SmtpClient( server );
client->Credentials = CredentialCache::DefaultNetworkCredentials;
Console::WriteLine( L"Sending an email message to {0} and {1}.", to->DisplayName, message->Bcc );
try
{
client->Send( message );
}
catch ( Exception^ ex )
{
Console::WriteLine(L"Exception caught in CreateBccTestMessage(): {0}",
ex->ToString() );
}
client->~SmtpClient();
}
public static void CreateBccTestMessage(string server)
{
MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller");
MailAddress to = new MailAddress("jane@contoso.com", "Jane Clayton");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an email message from an application very easily.";
MailAddress bcc = new MailAddress("manager1@contoso.com");
message.Bcc.Add(bcc);
SmtpClient client = new SmtpClient(server);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
Console.WriteLine("Sending an email message to {0} and {1}.",
to.DisplayName, message.Bcc.ToString());
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateBccTestMessage(): {0}",
ex.ToString());
}
}
備註
包含非 ASCII 字元的顯示名稱會以人類可讀取的形式傳回。 ToString使用方法來取得的DisplayName編碼形式。
用來讀取電子郵件的某些軟體程式會顯示 DisplayName 屬性值,而不是電子郵件位址,或除了電子郵件位址之外。