문제
Moble Phone (내 전화)에서 이메일 텍스트로 전송되는 GPS 데이터를 얻기 위해 Gmail 계정을 읽으려고합니다.
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의 경험이 있습니까?
해결책 3
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--;
}
}
다른 팁
팝 프로토콜을 사용하여 이메일을 읽은 것으로 표시 할 수 없습니다.
IMAP를 사용해보십시오.
cl.port = 995;
C#Mail에 대한 경험이 없으며이 답변은 도움이되지 않을 수 있지만 이메일 보내기/수신 관련 코드를 작성하려고하는 동안 과거에 이상 함을 경험했습니다.
우리가 직장에서 실행중인 바이러스 백신 소프트웨어는 허용 된 .exe의 화이트리스트가있어/아웃 바운드 POP3 또는 SMTP 연결을 만들 수 있습니다. 이것이 당신의 문제 일 가능성이 있습니까?
제휴하지 않습니다 StackOverflow