VCL How To - Indy 元件篇 |
|
bruce0211
版主 ![]() ![]() ![]() ![]() ![]() 發表:157 回覆:668 積分:279 註冊:2002-06-13 發送簡訊給我 |
元件名稱:TIdSMTP & TIdMessage
文件版本:for Delphi
文件作者:鈴鐺(LinDaniel) 2002/09/2 ●[元件簡介] TIdSMTP是用來發信的元件,使用起來,幾乎只要設定參數即可,方便易用.
TIdMessage 則代表信件本文的元件, 除了可搭配 TIdSMTP 寄信外, 也可運用在POP3收信, NNTP新聞群組. ●[範例說明]
發一封有附件的信,使用方式 Form 上面放 TIdSMTP(Indy Client), TIdMessage(Indy Misc),Buuton,Memo
procedure TForm1.Button1Click(Sender: TObject); begin with IdMessage1 do begin Clear; // 清除前一次產生的 body & headerm, 以免第二次按時重複 Body.Assign(Memo1.Lines); From.Text := 'from@xxx.com'; // 寄件者 Recipients.EMailAddresses := 'to@xxx.com'; // 收件者 Subject := 'subject 主題'; //Priority := TIdMessagePriority(2); // 0-4, 0表示最高優先順序 //CCList.EMailAddresses := 'a@a.com;b@b.com'; //BccList.EMailAddresses := 'd@d.com;e@e.com'; ReceiptRecipient.Text := ''; // ReceiptRecipient.Text := From.Text; //若要寄件回函,改成這行 end; // 附加的檔案 TIdAttachment.Create(IdMessage1.MessageParts, 'c:\t1.zip'); TIdAttachment.Create(IdMessage1.MessageParts, 'c:\t2.zip'); //SMTP server 認證的方式 IdSMTP1.AuthenticationType := atNone; // 不用認證,要認證改為下面三行 //IdSMTP1.AuthenticationType := atLogin; {Simple Login} //IdSMTP1.Username := 'user'; //IdSMTP1.Password := 'password'; //一般設定 IdSMTP1.Host := 'smtp.test.com'; IdSMTP1.Port := 25; //寄送 try IdSMTP1.Connect; try IdSMTP1.Send(IdMessage1); ShowMessage('E-Mail 已寄出'); finally IdSMTP1.Disconnect; end; except on e: exception do begin ShowMessage('Mail 寄送失敗:' e.Message); end; end; end;●[使用經驗] 參考 indy 8.1 sample code "MailClient2"(Delphi 6 附的 MailClient 似乎是較舊版) 發表人 - bruce0211 於 2002/09/11 17:16:14 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |