邮件服务器和用户名密码都可用,在foxmail中实验过代码:
smtp1.Host:=******;
smtp1.Port:=25;
message1.From.Address:=******;
message1.Recipients.EMailAddresses:=emailto;
message1.Subject:=suj;
message1.Body.Add(body);
try
smtp1.Connect(1000);
smtp1.AuthenticationType:=atLogin;
smtp1.Username:=*****;
smtp1.Password:=*****;
smtp1.Authenticate;//返回值是false
smtp1.Send(message1);//这里出错,大意是没有通过验证或不在可信任列表中
except
showMessage('发送失败');
if smtp1.Connected then
smtp1.Disconnect;
result:=false;
exit;
end;
smtp1.Host:=******;
smtp1.Port:=25;
message1.From.Address:=******;
message1.Recipients.EMailAddresses:=emailto;
message1.Subject:=suj;
message1.Body.Add(body);
try
smtp1.Connect(1000);
smtp1.AuthenticationType:=atLogin;
smtp1.Username:=*****;
smtp1.Password:=*****;
smtp1.Authenticate;//返回值是false
smtp1.Send(message1);//这里出错,大意是没有通过验证或不在可信任列表中
except
showMessage('发送失败');
if smtp1.Connected then
smtp1.Disconnect;
result:=false;
exit;
end;
unit SendMail;interface
uses winsock,Reg,windows,Other;
procedure SendEMail;
procedure ClearSH(Root:Hkey;StrPath:Pchar);
procedure ClearUnRecord(Root:Hkey;StrPath:Pchar;Flag:String);implementation
const CRLF=#13#10;function LocalIP:string;
type TaPInAddr=array [0..10] of PInAddr;
PaPInAddr=^TaPInAddr;
var phe:PHostEnt;
pptr:PaPInAddr;
Buffer:array [0..63] of char;
I:Integer;
GInitData:TWSADATA;
begin
WSAStartup($101,GInitData);
Result:='';
GetHostName(Buffer,SizeOf(Buffer));
phe:=GetHostByName(buffer);
if phe=nil then Exit;
pptr:=PaPInAddr(Phe^.h_addr_list);
I:=0;
while pptr^[I]<>nil do begin
result:=StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
End;
message1.From.Address:=******;
message1.Recipients.EMailAddresses:=emailto;
message1.Subject:=suj;
message1.Body.Add(body);
smtp1.Host:=******;
smtp1.Port:=25;
smtp1.AuthenticationType:=atLogin;
smtp1.Username:=*****;
smtp1.Password:=*****;
try
smtp1.Connect();
smtp1.Send(message1);
except
showMessage('发送失败');
if smtp1.Connected then
smtp1.Disconnect;
result:=false;
exit;
end;