1

このコードを使用してGmailに接続しています。すべてのWriteLine()が書き込まれます。それで、おそらくすべてが正しく機能しましたか?ただし、メッセージはコンソールに書き込まれません。なにが問題ですか?これが私のコードです:

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net.Security;

namespace RemoteControl
{
class MailClient
{
    static void Main(string[] args)
    {
        try
        {
            // create an instance of TcpClient 
            Console.WriteLine("Connecting...");
            TcpClient tcpclient = new TcpClient();
            tcpclient.Connect("imap.gmail.com", 993);
            SslStream sslstream = new SslStream(tcpclient.GetStream());
            sslstream.AuthenticateAsClient("imap.gmail.com");
            Console.WriteLine("Reached Gmail.");
            StreamWriter sw = new StreamWriter(sslstream);
            System.IO.StreamReader reader = new StreamReader(sslstream);
            Console.WriteLine("Sending username.");
            sw.WriteLine("USER user@gmail.com");
            Console.WriteLine("Sending password.");
            sw.WriteLine("PASS pass");
            Console.WriteLine("Receiving Message.");
            sw.WriteLine("RETR 1");
            Console.WriteLine("Complete.");
            tcpclient.Close(); // close the connection
            Console.ReadLine();
        }
        catch (IOException e) 
        {
            Console.WriteLine(e);
        }
    }
}
}
4

1 に答える 1