delphi 7郵件傳送程式編寫

2021-07-12 01:30:52 字數 1962 閱讀 5212

delphi 7傳送個郵件一般用到tidsmtp與tidmessage這兩個元件,他們分別在indy clients和indy misc兩個面板元件頁內,或者通過選單 view  -> component list裡面直接輸入控制項名字查詢控制項。

一般的郵件傳送用到前兩個控制項就可以了,但是現在許多郵箱需要通過ssl加密來傳送郵件,這樣還需要乙個控制項tidssliohandlersocket( indy i/o handler 頁面)和乙個ssl的dll

**如下:

procedure

tform1.btn_sendclick(sender: tobject);

varfilename:

string

;begin //傳送郵件主函式

tryidssliohandlersocket1.ssloptions.method:=sslvsslv3;

idsmtp1.iohandler:= idssliohandlersocket1; //區別在這兒喲

idsmtp1.authenticationtype:=atlogin; //設定登陸型別

idsmtp1.username:='

youename

'; //設定登陸帳號

idsmtp1.password:='

pasword

'; //設定登陸密碼

idsmtp1.host:='

smtp.gmail.com

'; //設定smtp位址

idsmtp1.port:=465; //設定埠 ,預設是25,gmail是465

ifnot idsmtp1.connected then

begin

idsmtp1.connect(

2000); //開始連線伺服器

end;

except

showmessage(

'連線失敗,請重試!');

exit; //連線失敗 的話 退出該執行過程

end; idmessage1.body.clear; //先清空上次傳送的內容

idmessage1.subject:='

delphi郵件傳送測試

'; //設定郵件傳送的標題

idmessage1.body.add(

'這是一封來之delphi 7編寫程式傳送來的電子郵件

'); //設定郵件傳送的主體

filename := '

c:\檔案.txt

'; //需要新增的附件檔案

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

idmessage1.from.address:= '

[email protected]

'; //設定郵件的發件人 也就是說該郵件來自什麼地方

idmessage1.from.name := '

tqs'

; idmessage1.recipients.emailaddresses:= '

[email protected]

'; //收件人的位址

idmessage1.cclist.emailaddresses:='

[email protected]

';//抄送

idmessage1.bcclist.emailaddresses:='

[email protected]

'; //密送

idmessage1.priority:=mphighest; //郵件重要性

tryidsmtp1.authenticate;

idsmtp1.send(idmessage1);

showmessage(

'傳送成功!');

except

showmessage(

'郵件傳送失敗!');

end;end;

delphi傳送郵件程式

unit unit1 inte ce uses windows,messages,sysutils,variants,classes,graphics,controls,forms,dialogs,idmessage,idbasecomponent,idcomponent,idtcpconnecti...

Delphi傳送郵件

首先在控制項欄定位到 indy clients新增控制項idsmtp 再定位到 indy misc新增控制項idmessage 傳送郵件函式 procedure tform1.sendmail yyuser string yypass string begin tryidsmtp1.authenti...

Delphi傳送郵件

首先在控制項欄定位到 indy clients加入控制項idsmtp 再定位到 indy misc加入控制項idmessage 傳送郵件函式 procedure tform1.sendmail yyuser string yypass string begin tryidsmtp1.authenti...