更新 : 2007 年 11 月
名前空間 :
System.Net.Mail アセンブリ :
System (System.dll 内)
Public Property UseDefaultCredentials As Boolean
Dim instance As SmtpClient
Dim value As Boolean
value = instance.UseDefaultCredentials
instance.UseDefaultCredentials = value
public bool UseDefaultCredentials { get; set; }
public:
property bool UseDefaultCredentials {
bool get ();
void set (bool value);
}
/** @property */
public boolean get_UseDefaultCredentials()
/** @property */
public void set_UseDefaultCredentials(boolean value)
public function get UseDefaultCredentials () : boolean
public function set UseDefaultCredentials (value : boolean)
一部の SMTP サーバーでは、サーバーがクライアントに代わって電子メールを送信する前に、クライアントが認証されている必要があります。この SmtpClient オブジェクトを、現在ログオンしているユーザーの既定の資格情報を使用して認証する必要がある (サーバーから要求されている場合) ときは、このプロパティを true に設定します。クライアント アプリケーションでは、ほとんどの場合、この動作が必要です。
資格情報は、アプリケーションまたはコンピュータの構成ファイルを使用して指定することもできます。詳細については、「<mailSettings> 要素 (ネットワーク設定)」を参照してください。
UseDefaultCredentials プロパティに false, が設定されると、Credentials プロパティに設定された値が、サーバーに接続する際の資格情報として使用されます。UseDefaultCredentials プロパティに false が設定され、Credentials プロパティが設定されていない場合、メールが匿名でサーバーに送信されます。
注意 : |
|---|
基本認証で資格情報を提供すると、クリア テキストでサーバーに送信されます。この場合、他のユーザーが資格情報を読み取って利用できてしまうため、セキュリティ上の問題が発生する可能性があります。 |
このプロパティを使用したコード例を次に示します。
public static void CreateTestMessage2(string server)
{
string to = "jane@contoso.com";
string from = "ben@contoso.com";
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";
SmtpClient client = new SmtpClient(server);
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.UseDefaultCredentials = true;
client.Send(message);
}
static void CreateTestMessage2( String^ server )
{
String^ to = L"jane@contoso.com";
String^ from = L"ben@contoso.com";
MailMessage^ message = gcnew MailMessage( from,to );
message->Subject = L"Using the new SMTP client.";
message->Body = L"Using this new feature, you can send an e-mail message from an application very easily.";
SmtpClient^ client = gcnew SmtpClient( server );
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client->UseDefaultCredentials = true;
client->Send( message );
client->~SmtpClient();
}
public static void CreateTestMessage2(String server)
{
String to = "jane@contoso.com";
String from = "ben@contoso.com";
MailMessage message = new MailMessage(from, to);
message.set_Subject("Using the new SMTP client.");
message.set_Body("Using this new feature, you can send an e-mail "
+ "message from an application very easily.");
SmtpClient client = new SmtpClient(server);
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.set_UseDefaultCredentials(true);
client.Send(message);
} //CreateTestMessage2
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
.NET Framework
サポート対象 : 3.5、3.0、2.0
参照