用Indy建立收發電子郵件的例子

2021-04-21 23:27:33 字數 2857 閱讀 7966

1、建立工程,在窗體中加入idsmtp1、idmessage1和idpop31(indy控制項標籤組)控制項各乙個。

2、設定    idsmtp1.host := 'smtp.163.com';(我用的是163檢試,具體也可選擇其它伺服器)    idsmtp1.username :=

'caoyan528';(此處即表示郵箱的帳號名,例如郵箱為:[email protected],則username即為aaaaaa)    idsmtp1.password := '******xx';(此處

即為郵箱的密碼,如[email protected]郵箱密碼為123456,則password即為123456)。

3、設定idmessage1.from.address :=

'[email protected]';(注意,此處的郵箱位址應在smtp.163.com中存在且就為以上設定的username),idmessage1.recipients.emailaddre

端';(主題)具體源**如下:

procedure tform1.button4click(sender: tobject);

varfilename : string;

tmpemailitem : tidemailaddressitem;

// tmpemailadd :  tidemailaddresslist;

begin

tryidsmtp1.host := 'smtp.163.com';

idsmtp1.authenticationtype := atlogin; //保證登入模式為login

idsmtp1.username := 'caoyan_528';

idsmtp1.password := '******';

filename := 'e:/郵件傳送程式/2003-12-22_253_04.jpg';   //需要新增的附件檔案

tidattachment.create(idmessage1.messageparts,filename);  //新增附件

idmessage1.from.address := '[email protected]';

idmessage1.recipients.emailaddresses:='[email protected]';

tmpemailitem := idmessage1.recipients.add;  //新增乙個位址列表

tmpemailitem.text := '[email protected]'; //寫乙個收件人

idmessage1.bcclist.add.text := '[email protected]';  //書寫多個目標位址,實現**

idmessage1.bcclist.add.text := '[email protected]';  //書寫多個目標位址,實現**

idmessage1.subject:= '第乙個郵件客戶端';

idmessage1.body.text := memo1.text;   //此處為郵件正文

idmessage1.charset := 'gb2312';  //保證附件正文漢字的正常顯示

idmessage1.body.assign(memo1.lines);  

if idsmtp1.authschemessupported.indexof('login')>-1 then

begin

idsmtp1.authenticationtype := atlogin; //連線前要儲存為login  上面己設,此處不必要

idsmtp1.authenticate;

end;

idsmtp1.connect();  //連線smtp伺服器

idsmtp1.authenticate;

idsmtp1.send(idmessage1);  //向伺服器傳送郵箱

finally

idsmtp1.disconnect;  //斷開與伺服器的連線

end;

end;

自此,memo1中所寫的內容被當作郵件傳送了出去。而filename所指的附件也一同被傳送到了伺服器。

4、接收郵件

設定idpop31.host := pop.163.com      idpop31.username := 'caoyan_528';       idpop31.password:= '***xx';     

(此處的設定與smtp的設定相同)    源**如下:

procedure tform1.button5click(sender: tobject);

varmailcount : integer;

i : integer;

tmp : string;

begin

idpop31.connect();    //連線到pop3伺服器

mailcount := idpop31.checkmessages;  //得到郵箱郵件的各數

for i:=1 to mailcount do   //遍歷每一封郵件

begin

idmessage1.clear;

idpop31.retrieveheader(i,idmessage1);  //得到郵件的頭資訊

tmp := idmessage1.subject;      //得到郵件的標題

memo1.lines.add(tmp);

idpop31.retrieve(i,idmessage1);  //接收到郵件所有內容

tmp := idmessage1.body.text;   //郵件正文

memo1.lines.add(tmp);

end;

idpop31.disconnect;   //斷開連線

end; 

使用indy傳送電子郵件的注意點

用indy9.0.18元件傳送電子郵件很簡單,一般這樣就可以 1 對 qq.com,需要登入http mail.qq.com,在你的郵箱設定中去開通 允許pop3 smtp收發郵件 2 asmtpusername你要注意郵件服務商如何規定的,對 qq.com,只需要且只能輸入前面的 就可以了,而對於...

用Thinphp傳送電子郵件的方法

好長時間沒有動php了,突然想用thinkphp傳送電子郵件,可是查閱了書籍都寫的非常亂。沒有繼續看下去。這裡找到了乙個比較好的方法 第一步 首先我們要引入乙個外部類庫 mail.class.php 把它放到org的資料夾下 就是thinkphp的核心資料夾那一塊。假設還不明確,見下圖 第二步 在c...

登陸模組郵箱用例設計 電子郵件模組測試用例

序號 測試步驟 進入電子郵件功能模組 新建返回電子郵件功能選單,選擇進入郵箱設定 當已有郵箱設定但是未啟動的情況下,依次選擇進入除 了郵箱設定之外的功能 返回電子郵件功能選單,選擇進入郵箱設定 在已有郵箱設定開啟之後的情況下,選擇進入收發郵件 序號測試步驟 選擇電子郵件 新建,選擇乙個字尾,然後進入...