cedure TMainFrm.btnSendMailClick(Sender: TObject);
begin
try
if (Trim(edtCc.Text) = '') and (Trim(edtRsd.Text) = '') and (Trim(edtBCc.Text) = '') then
begin
MessageDlg('You should input Rsd, please check,thanks!', mtInformation, [mbOK], 0);
edtRsd.SetFocus;
Exit;
end;
with IdMessage do
begin
Clear;
Subject := edtSub.Text;
From.Text := edtUN.Text;
Recipients.EMailAddresses := edtRsd.Text;
CCList.EMailAddresses := edtCC.Text;
BccList.EMailAddresses := edtBCc.Text;
Priority := TIdMessagePriority(4);
if Trim(beAth.Text) <> '' then
begin
TIdAttachment.Create(MessageParts, Trim(beAth.Text));
end;
Body.Assign(mmBdy.Lines);
end;
except
on E: Exception do
begin
MessageDlg('Msg Set Failed with Err information [' + E.Message + ']', mtWarning, [mbOK], 0);
Exit;
end;
end;
try
if (Trim(edtUN.Text) = '') or (Trim(edtHst.Text) = '') or (Trim(edtPsd.Text) = '') then
begin
MessageDlg('You should input UN, please check,thanks!', mtInformation, [mbOK], 0);
edtUN.SetFocus;
Exit;
end;
with IdSMTP do
begin
if Connected then Disconnect;
AuthenticationType := atLogin;
Port := 25;
UserName := edtUN.Text;
Password := edtPsd.Text;
Host := edtHst.Text;
Connect;
end;
except
on E: Exception do
begin
MessageDlg('Srv Set Failed with Err information [' + E.Message + ']', mtWarning, [mbOK], 0);
Exit;
end;
end;
try
IdSMTP.Send(IdMessage);
IdSMTP.Disconnect;
MessageDlg('OK!', mtInformation, [mbOK], 0);
except
on E: Exception do
begin
MessageDlg('Send Failed with Err information [' + E.Message + ']', mtWarning, [mbOK], 0);
Exit;
end;
end;
end;
end.