应该用Delphi6和Delphi7的IdSMTP控件。IdSMTP支持认证发信,示例如下:
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
with IdMessage1 do
begin
Body.Assign(Memo1.Lines);
From.Address:=EditFromAdd.Text;
Recipients.EMailAddresses:=EditToAdd.Text;
TIdAttachment.Create(IdMessage1.MessageParts,EditAtt.Text);
Subject:='测试信件';
end;
//开始发送邮件
with IdSMTP1 do
begin
Host:=EditHost.Text;
Port:=25;
Username:=EditUser.Text;
Password:=EditPSW.Text;
try
Connect;
except
Showmessage('连接SMTP服务器失败!');
exit;
end;
try
Send(IdMessage1);
ShowMessage('测试邮件已经发送,请到邮箱检查是否收到!');
Finally
Disconnect;
end;
end;
end;