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. |
总结
以上所述是小编给大家介绍的Delphi - Indy idMessage和idSMTP实现邮件的发送,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!