........................
登陆主机
procedure tform1.BTN_CONNECTCLICK(sender:Tobject);
begin
idsmtp1.host:=ED_HOST.TEXT;
idsmtp1.port:=strtoint(ED_PORT.TEXT);
idsmtp1.username:=ED_USER_ID.TEXT;
idsmtp1.connect;
end;
断开
procedure tform1.BTN_DISCONNECTCLICK(sender:Tobject);
begin
idsmtp1.disconnect;
end;
增加附件
procedure tform1.BTN_ADDCLICK(sender:tobject);
begin
if opendialog1.execute then listbox1.items.add(opendialog.filename);
end;
取消附件
procedure Tform1.BTN_REMOVECLICK(sender:tobject);
begin
listbox1.items.delete(listbox1.itemindex);
end;
寄信
procedure Tform1.BTN_SENDCLICK(sender:tobject);
var i:integer;
s:string;
attachment:TIdAttachment;
begin
for i:=0 to listbox1.Items.Count-1 do
begin
s:=listbox1.Items.strings;
Attachment:=Tidattachment.create(Idmessage.messageparts,s);
end;
with IdMessage do
begin
form.text:=ED_SEND_EMAIL.text;
sender.text:=ED_SEND_NAME_text;
recipients.Emailaddresses:=ED_TO_ADDRESS.text;
cclist.EmailAddresses:=ED_TO_CC.text;
Bcclist.Emailaddresses:=ED_TO_BCC.text;
Subject:=ED_SUB.text;
body:=ED_TO_CONNECT.Lines;
end;
WITH Idsmtp1 DO
begin
statusbar1.SimpleText:='开始发送邮件';
Host:=ED_HOST.text;
try
Statusbar1.simpleText:='连接服务端';
Connect;
Statusbar1.simpleText:='连接成功,开始发送邮件';
Send(Idmessage);
Statusbar1.simpleText:='准备和服务器断开';
Disconnect;
Statusbar1.simpleText:='已经和服务器断开';
Except on E:exception DO
begin
if connected then disconnect;except end;
Statusbar1.simpleText:='邮件发送失败';
showmessage(e.message);
end;
end;
end;
Statusbar1.simpleText:='邮件已经发送成功';
end;
其他的自己补充吧 不知道有没写错字母,反正文本方式写的东西,我从没一次编译成功过。