idMessage / idSMTP
首先对idMessage类的各种属性进行赋值(邮件的基本信息,如收件人、邮件主题、邮件正文等),其次通过idSMTP连接邮箱服务器,最后通过idSMTP的Send方法将idMessage发送出去。
界面布局如下:
代码如下:
unit uMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, RzPanel, RzShellDialogs, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP, RzButton, StdCtrls, RzEdit, RzBtnEdt, Mask, RzLabel; type TMainFrm = class(TForm) gbMsgSet: TRzGroupBox; gbSrvSet: TRzGroupBox; lbSubject: TRzLabel; lbRsd: TRzLabel; lbCc: TRzLabel; lbBCc: TRzLabel; lbAth: TRzLabel; lbBdy: TRzLabel; lbUserName: TRzLabel; lbHost: TRzLabel; lbPsd: TRzLabel; edtSub: TRzEdit; edtRsd: TRzEdit; edtCc: TRzEdit; edtBCc: TRzEdit; beAth: TRzButtonEdit; mmBdy: TRzMemo; btnSendMail: TRzBitBtn; edtUN: TRzEdit; edtHst: TRzEdit; edtPsd: TRzEdit; IdSMTP: TIdSMTP; IdMessage: TIdMessage; odMain: TRzOpenDialog; procedure beAthButtonClick(Sender: TObject); procedure btnSendMailClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var MainFrm: TMainFrm; implementation {$R *.dfm} procedure TMainFrm.beAthButtonClick(Sender: TObject); begin with odMain do begin Execute; if FileName <> '' then begin beAth.Text := FileName; end; end; end; procedure 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实现邮件的发送,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
内蒙古资源网 Copyright www.nmgbbs.com
暂无“Delphi - Indy idMessage和idSMTP实现邮件的发送”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。