⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit3.~pas

📁 ceshi de bu yao xiazai
💻 ~PAS
字号:
unit Unit3;

interface

uses
  Messages, SysUtils, Variants, Classes, Graphics, Controls,StdCtrls, OleServer,
    IdComponent, IdTCPConnection, IdTCPClient, IdMessageClient,
  IdSMTP, IdBaseComponent, IdMessage,ActiveX;

type
  My_Thread = class(TThread)
  private
    IdMessage:TidMessage;
    IdSmtp:TidSmtp;
    { Private declarations }
  protected
    procedure Execute; override;
  public
    function SendMail(MailBody,MailSubject:string):string;
    constructor create(MailBd,MailSub:string);
    destructor destroy;override;
  end;

implementation

var
  MailText,MailSubj:string;

{ Important: Methods and properties of objects in VCL or CLX can only be used
  in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure My_Thread.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ My_Thread }
constructor My_Thread.create(MailBd,MailSub:string);
begin
  inherited Create(false);
  priority:=tpTimeCritical;
  freeOnterminate:=true;
  IdMessage:=TidMessage.Create(nil);
  IdSmtp:=TidSmtp.Create(nil);
  MailText:=MailBd;
  MailSubj:=MailSub;
end;

destructor My_Thread.destroy;
begin
  inherited destroy;
  IdMessage.Free;
  IdSmtp.Free;
end;

function My_Thread.SendMail(MailBody,MailSubject:string):string;
var
  TempBackupDirectory:string;
  i:integer;
  sender_name,rece_list,server_ip,server_port:string;
begin
  sender_name:='CP-IT1T/CPCHG/FOXCONN@FOXCONN';
  rece_list:='CP-IT1T/CPCHG/FOXCONN@FOXCONN';
  server_ip:='10.160.11.16';
  server_port:='25';
  IdMessage:=TidMessage.Create(nil);
  IdSmtp:=TidSmtp.Create(nil);
  try
    with IdMessage do
    begin
      from.Text:=sender_name;
      sender.Text:=sender_name;
      Recipients.EMailAddresses:=rece_list;
      subject:=MailSubject;
      body.Text:=MailBody;
    end;
    idsmtp.Host:=server_ip;
    idsmtp.Port:=strtoint(server_port);
    idsmtp.Connect;
    idsmtp.Send(idmessage);
    idsmtp.Disconnect;
    SendMail:='OK';
  except
    on e:exception do
    begin
      idsmtp.Disconnect;
      SendMail:=e.Message;
    end;
  end;
end;

procedure My_Thread.Execute;
begin
  Coinitialize(nil);
  SendMail(MailText,MailSubj);
  CoUninitialize;
  { Place thread code here }
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -