我正在使用此代码连接到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);
}
}
}
}
答案 0 :(得分:0)
**根据我的理解,您希望使用C#阅读电子邮件。如果是这样,我认为socket pop3是解决您的问题的不错选择。例如:**
{{1}}