unit u_crm_client_check_do; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, BusinessSkinForm, bsSkinCtrls, StdCtrls, Mask, DBCtrls, DB, ADODB, Psock, NMsmtp, IdComponent, IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP, IdBaseComponent, IdMessage; type Tfrm_crm_client_check_do = class(TForm) bsBusinessSkinForm1: TbsBusinessSkinForm; bsSkinButton3: TbsSkinButton; bsSkinButton2: TbsSkinButton; Label4: TLabel; DBEdit4: TDBEdit; DBEdit5: TDBEdit; Label5: TLabel; IdMsg: TIdMessage; SMTP1: TIdSMTP; procedure bsSkinButton2Click(Sender: TObject); procedure bsSkinButton3Click(Sender: TObject); procedure NMSMTP1Connect(Sender: TObject); private { Private declarations } public { Public declarations } end; var frm_crm_client_check_do: Tfrm_crm_client_check_do; implementation uses u_crm_client_check, u_data_share, my_sys_function; {$R *.dfm} procedure Tfrm_crm_client_check_do.bsSkinButton2Click(Sender: TObject); begin close; end; procedure Tfrm_crm_client_check_do.bsSkinButton3Click(Sender: TObject); var aQuery:TAdoQuery; str,emp,mail:String; begin try frm_crm_client_check.t_crm_client.edit; frm_crm_client_check.t_crm_client['客户状态']:='审核通过'; frm_crm_client_check.t_crm_client.post; except showmessage('审核通过失败!!'); exit; end; aQuery:=CreateAdoQuery; try aQuery.Close; aQuery.SQL.Clear; aQuery.SQL.Add('Select * from t_crm_client_sales where 结费类型=''约定时间'' and 客户简称='''+frm_crm_client_check.t_crm_client['客户简称']+''''); aQuery.Open; if not aQuery.IsEmpty then begin aQuery.Close; aQuery.SQL.Clear; aQuery.SQL.Add('Select * from t_sys_awoke where 提醒状态=''准备执行'' AND 提醒类别=''新客户提醒'' AND 开始日期<='''+FormatDateTime('YYYY-MM-DD',NOW)+''' and 结束日期>='''+FormatDateTime('YYYY-MM-DD',NOW)+''''); aQuery.Open; if not aQuery.IsEmpty then begin str:=Trim(aQuery.FieldByName('提醒内容').AsString); emp:=Copy(str,pos('复核=',str)+5,length(str)-pos('复核=',str)-3); mail:=GetEmail(emp); if mail<>'' then begin SMTP1.AuthenticationType := atLogin; SMTP1.username:= frm_data_share.t_sys_company.FieldByName('登录用户名').AsString; SMTP1.Password :=frm_data_share.t_sys_company.FieldByName('登录密码').AsString; SMTP1.Host :=frm_data_share.t_sys_company.FieldByName('SMTP服务器地址').AsString; SMTP1.Port :=Strtointdef(Trim(frm_data_share.t_sys_company.FieldByName('SMTP服务器端口').AsString),25); try SMTP1.Connect; except Showmessage('连接SMTP服务器失败!'); Exit; end; try with IdMsg do begin body.Clear; Body.Text :='客户名称:'+frm_crm_client_check.t_crm_client['客户简称']+'申请复核'; From.address :=frm_data_share.t_sys_company.FieldByName('SMTP邮箱名称').AsString; Recipients.EMailAddresses :=mail; Subject:='客户名称:'+frm_crm_client_check.t_crm_client['客户简称']+'申请复核'; end; SMTP1.Send(IdMsg); finally // showmessage(t_sys_awoke_emp.FieldByName('人员').asstring+'的信件已成功发送'); SMTP1.Disconnect; end; { NMSMTP1.Host:=frm_data_share.t_sys_company.FieldByName('SMTP服务器地址').AsString; NMSMTP1.Port:=Strtointdef(Trim(frm_data_share.t_sys_company.FieldByName('SMTP服务器端口').AsString),25); if NMSMTP1.Connected then begin NMSMTP1.Disconnect; end; NMSMTP1.Connect; NMSMTP1.PostMessage.FromAddress :=frm_data_share.t_sys_company.FieldByName('SMTP邮箱名称').AsString; NMSMTP1.PostMessage.FromName :='邮件自动提醒'; NMSMTP1.PostMessage.ToAddress.Text :=mail; NMSMTP1.PostMessage.Body.Text :='客户名称:'+frm_crm_client_check.t_crm_client['客户简称']+'申请复核'; NMSMTP1.PostMessage.Subject :='客户名称:'+frm_crm_client_check.t_crm_client['客户简称']+'申请复核'; NMSMTP1.SendMail; } end; end; end; finally FreeAndNil(aQuery); end; showmessage('审核通过成功!!'); close; end; procedure Tfrm_crm_client_check_do.NMSMTP1Connect(Sender: TObject); var StrUserName,strPassword:String; begin { strUserName:=EncodeString(frm_data_share.t_sys_company.FieldByName('登录用户名').AsString); strPassword:=EncodeString(frm_data_share.t_sys_company.FieldByName('登录密码').AsString); nmsmtp1.Transaction('EHLO') ; nmsmtp1.Transaction('AUTH LOGIN'); nmsmtp1.Transaction(strUserName); nmsmtp1.Transaction(strPassword); } end; end.