Indy的Pop3客户端的,怎么用啊

feier_miao 2003-01-16 03:49:12
我就是想做一个简单的收邮件程序,各位高手请指点,我对indy得pop3一点都不明白,最好能给我源代码。。。
谢谢,,。。。
...全文
119 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
duguyai 2003-01-27
  • 打赏
  • 举报
回复
假设控件name=pop
pop->Host="pop3.sina.com.cn";//主机名
pop->Userid="name";//user id
pop->PassWord="password";//user password
pop->Port : 端口号 一般用默认的即可
//-------------------------------
//需要时 pop->SocksInfo 可以设置 socks属性
//以上信息设置好后 调用下面方法连接pop3服务器
pop->Connect();
//--------------------
//连接后可以用pop->CheckMessages()返回邮件数目
int MailNum=pop->CheckMessages();
//定义和创建邮件消息对象
TIdMessage *dgy;
dgy=new TIdMessage(NULL);
//pop->Retrieve(const int,TIdMessage *)可以接受邮件int 为第几封邮件
//e.g.::
pop->Retrieve(MailNum,dgy);//接受最后一封到dgy
//通过消息指针你可以得到该邮件的相关属性 dgy->
//dgy->From->Text :: 来自地址(name,add)
//其他你自己看英文猜意思
//pop->Delete(const int) :: 可以删除底几封信

//最后接受完毕后 关闭连接 回收内存
pop->Disconnect();
delete dgy;
dgy=NULL;
zjqc 2003-01-24
  • 打赏
  • 举报
回复
这么长!一点注释都没有!头晕!
warton 2003-01-16
  • 打赏
  • 举报
回复
好,收藏
invalid 2003-01-16
  • 打赏
  • 举报
回复
贴核心函数给你吧。
void __fastcall TMainFrm::RetrievePOPHeaders(int inMsgCount )
{
AnsiString stTemp;
AnsiString stformat;
int intIndex;
TListItem *itm;

stTemp = StatusBar1->Panels->Items[1]->Text;
lvHeaders->Items->Clear();

for (intIndex = 1; intIndex <= inMsgCount; intIndex++)
{
// Clear the message properties
ShowStatus(stformat.sprintf("Messsage %d of %d", intIndex, inMsgCount));
Application->ProcessMessages();
Msg->Clear();
POP->RetrieveHeader(intIndex, Msg);
// Add info to ListView
itm = lvHeaders->Items->Add();
itm->ImageIndex = 5;
itm->Caption = Msg->Subject;
itm->SubItems->Add(Msg->From->Text);
itm->SubItems->Add(DateToStr(Msg->Date));
itm->SubItems->Add(IntToStr(POP->RetrieveMsgSize(intIndex)));
itm->SubItems->Add("n/a");
// itm.SubItems.Add(POP.RetrieveUIDL(intIndex));
}
ShowStatus(stTemp);
}
接收邮件:
void __fastcall TMainFrm::Retrievecurrentmessage1Click(TObject *Sender)
{
AnsiString stTemp;
int intIndex;
TListItem *li;

stTemp = StatusBar1->Panels->Items[1]->Text;
if (lvHeaders->Selected ==NULL)
return;

//initialise
ShowBusy(true);
Msg->Clear();
Memo1->Clear();
lvMessageParts->Items->Clear();
From->Caption = "";
Cc->Caption = "";
Subject->Caption = "";
Date->Caption = "";
Receipt->Caption = "";
Organization->Caption = "";
Priority->Caption = "";
pnlAttachments->Visible = false;

//get message and put into MSG
ShowStatus("Retrieving message " + lvHeaders->Selected->SubItems->Strings[3] );
POP->Retrieve(lvHeaders->Selected->Index + 1, Msg);
StatusBar1->Panels->Items[0]->Text = lvHeaders->Selected->SubItems->Strings[3];

//Setup fields on screen from MSG
From->Caption = Msg->From->Text;
Recipients->Caption = Msg->Recipients->EMailAddresses;
Cc->Caption = Msg->CCList->EMailAddresses;
Subject->Caption = Msg->Subject;
Date->Caption = FormatDateTime("dd mmm yyyy hh:mm:ss", Msg->Date);
Receipt->Caption = Msg->ReceiptRecipient->Text;
Organization->Caption = Msg->Organization;

Priority->Caption = IntToStr((unsigned char)Msg->Priority + 1);
// Priority->Caption = IntToStr(Ord(Msg.Priority) + 1);

//Setup attachments list
ShowStatus("Decoding attachments (" + IntToStr(Msg->MessageParts->Count) + ")");

// for (intIndex = 0; intIndex<= pred(Msg->MessageParts->Count) ;intIndex++)
for (intIndex = 0; intIndex < (Msg->MessageParts->Count) ;intIndex++)
{
if (dynamic_cast<TIdAttachment*>(Msg->MessageParts->Items[intIndex]))
{
//general attachment
pnlAttachments->Visible = true;
li = lvMessageParts->Items->Add();
li->ImageIndex = 8;
li->Caption = ExtractFilePath(ParamStr(0)) + dynamic_cast<TIdAttachment*>(Msg->MessageParts->Items[intIndex])->FileName;
}
else
{
//body text
if (dynamic_cast<TIdText*>(Msg->MessageParts->Items[intIndex] ))
{
Memo1->Lines->Clear();
Memo1->Lines->AddStrings(dynamic_cast<TIdText*>(Msg->MessageParts->Items[intIndex])->Body);
}
}
}
ShowStatus(stTemp);
ShowBusy(false);
void __fastcall TMainFrm::CheckMailExecute(TObject *Sender)
{
ShowBusy(true);
ShowStatus("Connecting....");

if(POP->Connected())
{
POP->Disconnect();
}
POP->Host = Pop3ServerName;
POP->Port = Pop3ServerPort;
POP->Username = Pop3ServerUser;
POP->Password = Pop3ServerPassword;
Application->ProcessMessages();
Application->ProcessMessages();
Application->ProcessMessages();
POP->Connect();
ToggleStatus(true,true);
FMsgCount = POP->CheckMessages();
FMailBoxSize = POP->RetrieveMailBoxSize()/1024;
ShowFileStatus();
if (FMsgCount > 0)
{
ShowFileStatus();
RetrievePOPHeaders(FMsgCount);
}
else
{
ShowStatus("No messages on server");
}

if(POP->Connected())
{
POP->Disconnect();
}
ToggleStatus(false,true);
ShowBusy(false);
}
//---------------------------------------------------------------------------
void __fastcall TMainFrm::RetrieveExecute(TObject *Sender)
{
if(!POP->Connected())
{
POP->Connect();
}

AnsiString LocalAttachmentfilename;
AnsiString RecievedAttachmentfilename;
AnsiString stTemp;
int intIndex;
TListItem *li;

stTemp = StatusBar1->Panels->Items[1]->Text;
if (lvHeaders->Selected ==NULL)
return;

//initialise
ShowBusy(true);
Msg->Clear();
Memo1->Clear();
lvMessageParts->Items->Clear();
From->Caption = "";
Cc->Caption = "";
Subject->Caption = "";
Date->Caption = "";
Receipt->Caption = "";
Organization->Caption = "";
Priority->Caption = "";
pnlAttachments->Visible = false;

//get message and put into MSG
ShowStatus("Retrieving message " + lvHeaders->Selected->SubItems->Strings[3] );
int msgnum=lvHeaders->Selected->Index + 1;
POP->Retrieve(msgnum, Msg);
StatusBar1->Panels->Items[0]->Text = lvHeaders->Selected->SubItems->Strings[3];

//Setup fields on screen from MSG
From->Caption = Msg->From->Text;
Recipients->Caption = Msg->Recipients->EMailAddresses;
Cc->Caption = Msg->CCList->EMailAddresses;
Subject->Caption = Msg->Subject;
Date->Caption = FormatDateTime("dd mmm yyyy hh:mm:ss", Msg->Date);
Receipt->Caption = Msg->ReceiptRecipient->Text;
Organization->Caption = Msg->Organization;

Priority->Caption = IntToStr((unsigned char)Msg->Priority + 1);

//Setup attachments list
ShowStatus("Decoding attachments (" + IntToStr(Msg->MessageParts->Count) + ")");
Memo1->Lines->Clear();
for (intIndex = 0; intIndex < (Msg->MessageParts->Count) ;intIndex++)
{
if (dynamic_cast<TIdAttachment*>(Msg->MessageParts->Items[intIndex]))
{ //general attachment
pnlAttachments->Visible = true;
li = lvMessageParts->Items->Add();
li->ImageIndex = 8;
RecievedAttachmentfilename= dynamic_cast<TIdAttachment*>(Msg->MessageParts->Items[intIndex])->FileName;

TIdAttachment*e=dynamic_cast<TIdAttachment*>(Msg->MessageParts->Items[intIndex]);
LocalAttachmentfilename=ExtractFilePath(ParamStr(0));
LocalAttachmentfilename=LocalAttachmentfilename + "ATTACH\\";//add attach folder name to store locally in sub folder
LocalAttachmentfilename=LocalAttachmentfilename + RecievedAttachmentfilename;
li->Caption=LocalAttachmentfilename;
if (e!=NULL)
e->SaveToFile(LocalAttachmentfilename);
}
else
{//body text
if (dynamic_cast<TIdText*>(Msg->MessageParts->Items[intIndex] ))// then
{
Memo1->Lines->AddStrings(dynamic_cast<TIdText*>(Msg->MessageParts->Items[intIndex])->Body);
}
}
}
ShowStatus(stTemp);
if (POP->Connected())
{
POP->Disconnect();
}

ShowBusy(false);
invalid 2003-01-16
  • 打赏
  • 举报
回复
indy自己带的有例子了。我以前从indy的网站上下载过.你去找找吧,找不着了给我发消息。
RomanticProgrammer 2003-01-16
  • 打赏
  • 举报
回复
问Invalid那个牛人吧..

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧