阅读邮件 [英] Read Mail
本文介绍了阅读邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
TcpClient tcpclient = new TcpClient(); // create an instance of TcpClient
tcpclient.Connect("pop.gmail.com", 995); // HOST NAME POP SERVER and gmail uses port number 995 for POP
System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream()); // This is Secure Stream // opened the connection between client and POP Server
sslstream.AuthenticateAsClient("pop.gmail.com"); // authenticate as client
bool flag = sslstream.IsAuthenticated; // check flag
System.IO.StreamWriter sw = new StreamWriter(sslstream); // Asssigned the writer to stream
System.IO.StreamReader reader = new StreamReader(sslstream); // Assigned reader to stream
sw.WriteLine("username"); // refer POP rfc command, there very few around 6-9 command
sw.Flush(); // sent to server
sw.WriteLine("password");
sw.Flush();
sw.WriteLine("RETR 2"); // this will retrive your first email
sw.Flush();
sw.WriteLine("Quit "); // close the connection
sw.Flush();
string str = string.Empty;
string strTemp = string.Empty;
while ((strTemp = reader.ReadLine()) != null)
{
if (strTemp == ".") // find the . character in line
{
break;
}
if (strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
Response.Write(str);
Response.Write("<BR>" + "Congratulation.. ....!!! You read your first gmail email ");
我使用上述代码阅读了一封邮件,但它只是加密格式.!
在此帮助我
谢谢
I read a mail using above code but it comes only encrypted format.!
Help me in this
Thanks
推荐答案
加密"到底是什么意思?请提供结果示例.
What exactly does ''encrypted'' mean? Please provide an example of your result.
邮件具有特殊格式,由 RFC 5322定义 [ ^ ]和一些 ^ ]类型用于不同类型的邮件.它通常包含消息头和正文.您需要解析邮件以获取所有信息和实际邮件.
Mails have a special format which is defined by RFC 5322[^] and some MIME[^] types for different kinds of mails. It will generally contain Message Header and body. You need to parse the mail to get all the information and the actual mail.
这篇关于阅读邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文