BCB中接收邮件的例子

来源:互联网 发布:保健品有用吗 知乎 编辑:程序博客网 时间:2024/06/15 00:23

来自CSDN的 OnlyUx() 

//-------------------------从name1@163.com里取出邮件------------------
  Label1->Caption="正在连接服务器...";
  if(NMPOP31->Connected)NMPOP31->Disconnect();
  NMPOP31->AttachFilePath = ".";
  NMPOP31->DeleteOnRead = false;
  NMPOP31->ReportLevel = Status_Basic;
  NMPOP31->TimeOut = 20000;
  NMPOP31->Host ="Pop3.163.com";
  NMPOP31->Port=110;
  NMPOP31->UserID ="name2";
  NMPOP31->Password ="密码";
  NMPOP31->Connect();
  Label1->Caption="连接服务器成功,读取中,请稍后...";

  if(NMPOP31->MailCount)
{
   ListView1->Clear();
   str=NMPOP31->MailCount;
   for(int i=1;i<=NMPOP31->MailCount;i++)
     {
       NMPOP31->GetMailMessage(i);
       TListItem *listitem;
       listitem=ListView1->Items->Add();
       listitem->Caption=NMPOP31->MailMessage->From;
       listitem->SubItems->Add(NMPOP31->MailMessage->Subject);
       listitem->SubItems->Add(NMPOP31->MailMessage->Body);
     }
   Label1->Caption="读取完成,相关信息"+str+"条";
   NMPOP31->Disconnect();
   Memo1->Clear();
}
else
 {
   Label1->Caption="暂时没有邮件";
   return;
 }
}