我正在尝试阅读gmail帐户以获取从手机(我的手机)发送的gps数据(在电子邮件的文本中)
using (Pop3Client cl = new Pop3Client())
{
cl.UserName = "crash893";
cl.Password = "password";
cl.ServerName = "pop.gmail.com";
cl.AuthenticateMode = Pop3AuthenticateMode.Pop;
cl.Ssl = true;
cl.Authenticate();
///Get first mail of my mailbox
Pop3Message mg = cl.GetMessage(1); <<<<<<<<<< ERROR
String MyText = mg.BodyText;
///If the message have one attachment
Pop3Content ct = mg.Contents[0];
///you can save it to local disk
ct.DecodeData("c:\\test.txt");
}
但我在“获取第一封邮箱邮件
”时遇到异常"Higuchi.Net.Pop3.Pop3ConnectException: Pop3 connection is closed
at Higuchi.Net.Pop3.Pop3Client.SendCommand(String inCommand)
at Higuchi.Net.Pop3.Pop3Client.Execute(String inCommand, Boolean inIsMultiLine)
at Higuchi.Net.Pop3.Pop3Client.Execute(Pop3Command inCommand)
at Higuchi.Net.Pop3.Pop3Client.GetMessage(Int64 inMailIndex)"}
理想情况下,我想要打开这个读取此帐户中所有新未读电子邮件的特定主题行,然后读取正文中的数据并将其标记为已读
有谁知道它出错的原因
有没有人对c#mail有任何经验,嘿可以指出我正确的方向阅读和制作电子邮件阅读等
答案 0 :(得分:2)
无法使用POP协议将电子邮件标记为已读。
尝试使用IMAP。
答案 1 :(得分:2)
cl.Port = 995;
答案 2 :(得分:1)
using (Pop3Client cl = new Pop3Client())
{
cl.UserName = "ewgsdssw";
cl.Password = "sdgwsegw";
cl.ServerName = "pop.gmail.com";
cl.AuthenticateMode = Pop3AuthenticateMode.Pop;
cl.Port = 995;
cl.Ssl = true;
cl.Authenticate();
///Get first mail of my mailbox
///
int total = Convert.ToInt16(cl.GetTotalMessageCount());
while (total >= 1)
{
Pop3Message mg = cl.GetMessage(total);
if (mg.Subject == "I am Here")
{
// http://maps.google.com/maps?q=38.89552,-77.43265
//(+/- 76 metres.)
string location = mg.BodyText;
location = location.Replace("http://maps.google.com/maps?q=","~");
location = location.Replace("metres.)\r\n\r\n","~");
location = location.Split('~')[1];
location = location.Replace("(+/- ", ",");
location = location.Replace("\r\n", "");
string[] data = location.Split(',');
string lat = data[0];
string lon = data[1];
string res = data[2];
DateTime time = mg.Date;
textBox1.AppendText(string.Format("Lat: {0} LON: {1} Res: {2} TIME: {3}\r\n",lat,lon,res,time.ToString()));
}
total--;
}
}
答案 3 :(得分:0)
我没有使用C#Mail的经验,这个答案可能无济于事,但我在尝试编写电子邮件发送/接收相关代码时经历过一些奇怪。
原来我们在工作中运行的防病毒软件有一个允许.EXE的白名单,可以进行/出站POP3或SMTP连接。这有什么可能是你的问题吗?