function TCreatServer.Mail: Boolean; //发信
begin
Result := False;
with MailMessage do begin
Clear;
subject := 'test';
Body.Append('test test test');
from.Address := trim(Edit1.Text);
recipients.EMailAddresses := trim(Edit1.Text);
end;
with IdSMTP1 do begin
Host := trim(Edit2.Text);
Username := trim(Edit3.Text);
Password := trim(Edit4.Text);
end;
try
Caption := '正在连接服务器……';
IdSMTP1.Connect;
except
Caption := '失败!连接不了服务器!';
Exit;
end;
try
if (IdSMTP1.AuthSchemesSupported.IndexOf('LOGIN') <> -1) then begin
Caption := '正在连接进行身份验证……';
IdSMTP1.AuthenticationType := Atlogin;
if IdSMTP1.Authenticate then Caption := '身份验证成功!正在发送邮件……'
else Caption := '身份验证失败!'
end;
IdSMTP1.Send(MailMessage);
ShowMessage('发送邮件成功!请去邮箱确认一下你已经收到了测试信');
Result := True;
finally
IdSMTP1.Disconnect;
end;
end;