4

OpenPop.NETクライアントを使用して、Pop3プロトコルを介してメールボックスにアクセスしています。メッセージを削除できないという1つのことを除いて、すべて問題ありません。公式サイトからのサンプルでも役に立ちません。私はいくつかのメールサーバーでそれを試しました:gmail.com、yandex.ru、rambler.ruの状況は同じです。

更新-コードを追加しました。

static void Main(string[] args)
{
    DeleteMessageOnServer("pop.gmail.com", 995, true, USERNAME, PASSWORD, 1);
}

public static void
    DeleteMessageOnServer(string hostname, int port, bool useSsl, string username,
    string password, int messageNumber)
{
    // The client disconnects from the server when being disposed
    using (Pop3Client client = new Pop3Client())
    {
        // Connect to the server
        client.Connect(hostname, port, useSsl);

        // Authenticate ourselves towards the server
        client.Authenticate(username, password);

        // Mark the message as deleted
        // Notice that it is only MARKED as deleted
        // POP3 requires you to "commit" the changes
        // which is done by sending a QUIT command to the server
        // You can also reset all marked messages, by sending a RSET command.
        client.DeleteMessage(messageNumber);

        // When a QUIT command is sent to the server, the connection between them are closed.
        // When the client is disposed, the QUIT command will be sent to the server
        // just as if you had called the Disconnect method yourself.
    }
}
4

2 に答える 2

5

メソッドによってマークされた電子メールの削除は、メソッドが呼び出され.DeleteMessage(messageNumber);たときに発生します。.Disconnect();

于 2012-11-02T02:33:13.697 に答える
1

上記のように、接続が閉じられるとメールは削除されます。また、メッセージ番号はゼロではなく 1 で始まる必要があります。gmail の場合、「設定 -> POP/IMAP の転送 -> メッセージが POP でアクセスされたとき」に移動し、「gmail のコピーを削除」を選択する必要があります。

ここで確認できます。

于 2020-05-13T22:22:52.560 に答える