如何使用asp.net从gmail读取电子邮件 [英] How to read email from gmail using asp.net
本文介绍了如何使用asp.net从gmail读取电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用asp.net从gmail中读取电子邮件
How to read email from gmail using asp.net
推荐答案
检查一下. 使用Gmail帐户发送带有附件的电子邮件 [ ^ ],但这是用于发送.
请参见使用C#的IMAP客户端库 [如何使用IMAP协议访问电子邮件 [ ^ ]用于通过IMAP界面阅读电子邮件.
Check this out. Using Gmail Account to Send Emails With Attachment[^], but that is for sending.
See IMAP Client library using C#[^] and How to Access Emails Using the IMAP Protocol[^] for reading email via IMAP interface.
嗨 我几个星期前遇到了同样的问题.我已经通过使用 http://www.lesnikowski.com/ [
Hi I a couple weeks ago I had the same problem. I''ve solved it by using mail component by http://www.lesnikowski.com/[^]. It is not free but not so expensive.
Regards
Robert
您可以使用Outlook访问Gmail电子邮件
如果不是,则登录www.gmail.com,单击设置=>流行=>检查以访问Gmail Web客户端之外的电子邮件
You are able to access your gmail email using outlook
if not then login to www.gmail.com click on settings => pop => check to access email outside gmail web client
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;
protected void Button9_Click(object sender, EventArgs e)
{
try
{
// create an instance of TcpClient
TcpClient tcpclient = new TcpClient();
// HOST NAME POP SERVER and gmail uses port number 995 for POP
tcpclient.Connect("pop.gmail.com", 995);
// This is Secure Stream // opened the connection between client and POP Server
System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream());
// authenticate as client
sslstream.AuthenticateAsClient("pop.gmail.com");
//bool flag = sslstream.IsAuthenticated; // check flag
// Asssigned the writer to stream
System.IO.StreamWriter sw = new StreamWriter(sslstream);
// Assigned reader to stream
System.IO.StreamReader reader = new StreamReader(sslstream);
// refer POP rfc command, there very few around 6-9 command
sw.WriteLine("USER your_gmail_user_name@gmail.com");
// sent to server
sw.Flush();
sw.WriteLine("PASS your_gmail_password");
sw.Flush();
// this will retrive your first email
sw.WriteLine("RETR 1");
sw.Flush();
// close the connection
sw.WriteLine("Quit ");
sw.Flush();
string str = string.Empty;
string strTemp = string.Empty;
while ((strTemp = reader.ReadLine()) != null)
{
// find the . character in line
if (strTemp == ".")
{
break;
}
if (strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
Response.Write(str);
Response.Write("<BR>" + "Congratulation.. ....!!! You read your first gmail email ");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
这篇关于如何使用asp.net从gmail读取电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文