DELPHI发送邮件源代码


本文整理自网络,侵删。

 DELPHI发送邮件源代码

测试环境Delphi 10.1 Berlin 和Delphi7

主要控件为indy中  IdSMTP 和 IdMessage

主要代码:

procedure TForm1.SendMail;
begin
  if (Edit1.Text = '') or (Edit2.Text = '') or (Edit3.Text = '') then
    showmessage('请完整输入信息!')
  else
  begin
    try
      IdSMTP1.Username := Edit1.Text; // 设置登陆帐号
      IdSMTP1.Password := Edit2.Text; // 设置登陆密码
      IdSMTP1.Host := Edit3.Text; // 设置SMTP地址
      IdSMTP1.Connect; // 开始连接服务器
    except
      showmessage('连接失败,请重试!');
      Exit; // 连接失败 的话 退出该执行过程
    end;
    IdMessage1.Body.Clear; // 先清空上次发送的内容 www.delphitop.com
    IdMessage1.CharSet := 'GB2312'; // 不设置这个中文会乱码
    IdMessage1.Subject := Edit4.Text; // 设置邮件发送的标题
    IdMessage1.Body.Text := Memo1.Lines.Text; // 设置邮件发送的主题
    IdMessage1.From.Address := Edit1.Text; // 设置邮件的发件人
    IdMessage1.Recipients.EMailAddresses := Edit5.Text; // 收件人的地址
    try
      IdSMTP1.Send(IdMessage1);
      showmessage('邮件发送成功!');
    except
      showmessage('邮件发送失败!');
    end;
  end;
end;

相关阅读 >>

Delphi 读取utf-8格式的文件内容

Delphi link() 精简打开网址

Delphi tchart使用经验小结

Delphi 获取当前目录下的.txt文本不要带后缀扩展名

Delphi 字符串加密解密代码

Delphi 用内存流文件流资源生成客户端

Delphi jpg图像加文字水印

Delphi 利用sendinput模拟鼠标键盘

Delphi wmi 获取网络信息

Delphi 如何读取文件头 判断文件类型

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...