.NET Framework クラス ライブラリ
SmtpClient..::.UseDefaultCredentials プロパティ

更新 : 2007 年 11 月

DefaultCredentials が要求と共に送信されるかどうかを制御する Boolean 値を取得または設定します。

名前空間 :  System.Net.Mail
アセンブリ :  System (System.dll 内)

構文

Visual Basic (宣言)
Public Property UseDefaultCredentials As Boolean
Visual Basic (使用法)
Dim instance As SmtpClient
Dim value As Boolean

value = instance.UseDefaultCredentials

instance.UseDefaultCredentials = value
C#
public bool UseDefaultCredentials { get; set; }
Visual C++
public:
property bool UseDefaultCredentials {
    bool get ();
    void set (bool value);
}
J#
/** @property */
public boolean get_UseDefaultCredentials()
/** @property */
public  void set_UseDefaultCredentials(boolean value)
JScript
public function get UseDefaultCredentials () : boolean
public function set UseDefaultCredentials (value : boolean)

プロパティ値

型 : System..::.Boolean

既定の資格情報が使用される場合は true。それ以外の場合は false。既定値は false です。

例外

例外条件
InvalidOperationException

電子メールが送信中の場合、このプロパティの値は変更できません。

解説

一部の SMTP サーバーでは、サーバーがクライアントに代わって電子メールを送信する前に、クライアントが認証されている必要があります。この SmtpClient オブジェクトを、現在ログオンしているユーザーの既定の資格情報を使用して認証する必要がある (サーバーから要求されている場合) ときは、このプロパティを true に設定します。クライアント アプリケーションでは、ほとんどの場合、この動作が必要です。

資格情報は、アプリケーションまたはコンピュータの構成ファイルを使用して指定することもできます。詳細については、「<mailSettings> 要素 (ネットワーク設定)」を参照してください。

UseDefaultCredentials プロパティに false, が設定されると、Credentials プロパティに設定された値が、サーバーに接続する際の資格情報として使用されます。UseDefaultCredentials プロパティに false が設定され、Credentials プロパティが設定されていない場合、メールが匿名でサーバーに送信されます。

注意 :

基本認証で資格情報を提供すると、クリア テキストでサーバーに送信されます。この場合、他のユーザーが資格情報を読み取って利用できてしまうため、セキュリティ上の問題が発生する可能性があります。


このプロパティを使用したコード例を次に示します。

C#
        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);
        }
Visual C++
   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();
   }


J#
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
参照

参照

タグ :


Page view tracker