質問
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を使った経験がありますが、電子メールを読んだり読んだりするなどの正しい方向を教えてくれます
解決 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--;
}
}
他のヒント
POPプロトコルを使用して、電子メールを既読としてマークすることはできません。
IMAPを使用してみてください。
cl.Port = 995;
私はC#Mailの経験がなく、この回答は役に立たないかもしれませんが、過去に電子メールの送受信に関連するコードを記述しようとしていたときに奇妙な経験をしました。
職場で実行しているウイルス対策ソフトウェアには、POP3またはSMTPのイン/アウト接続を許可する許可された.EXEのホワイトリストが含まれていました。これはあなたの問題ですか?
所属していません StackOverflow