使用组件:IdSMTP IdMessage
代码需要修改才能用,懒得改啦,自己参照一下就好啦


procedure Tform1.sendmail(host:string;name:string;password:string;mailadress:string;fromtext:string);
var
   smtp:TIdSMTP;
   msgsend:TIdMessage;
   csfs1:Boolean;
   csfs2:Boolean;

begin
  if (LabeledEdit2.Text='') or (LabeledEdit4.Text='')  then
  begin
    ShowMessage('请认真填表');
    Exit;
  end;

     if(i > 3) then   //可设置提交最大次数
     begin
       ShowMessage('您发送的申请太多啦,请歇一歇吧');
       Exit;
     end;
     i:=i+1;
     csfs1:=true; //*.txt附件传输开关
     csfs2:=true; //文本传输开关
    smtp := TIdSMTP.Create(nil);
    smtp.AuthenticationType := atLogin;
    smtp.Host := host;
    smtp.Username := name;
    smtp.Password := password;
    msgsend := TIdMessage.Create(nil);
    msgsend.Recipients.EMailAddresses := mailadress;
    msgsend.From.Text := fromtext;
    msgsend.Subject := '注册表单';
    msgsend.Body.Clear;
     msgsend.Body.Add('班级:'+labeledEdit2.text);//邮件内容
     Memo1.Lines:=msgsend.Body;
     Memo1.Lines.SaveToFile('表单.txt');//提交附件名
     if  csfs1 then
     TIdAttachment.Create(msgsend.MessageParts, '表单.txt');
     if  not csfs2 then
     msgsend.Body.Clear;
  try
  smtp.Connect();
      try
      smtp.Authenticate;
      smtp.Send(msgsend);
        ShowMessage('提交成功');
      except
        if temp then
        begin
         ShowMessage('提交失败');
         Application.Terminate;
         end;
        temp:=True;
      end;
  except
  ShowMessage('无法连接服务器!');
  end;
smtp.Disconnect;

end;

最后修改日期:2012 年 8 月 10 日

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。