需要引用
Sysutils,INIFiles,swsystem
保存邮件配置文件
procedure TformMain9.IWButton1Click(Sender: TObject);
var oinifileo:Tinifile;
begin
if ((iwedit1.Text<>'') and (iwedit2.Text<>'') and (iwedit3.Text<>'')) then
begin
oinifileo:=Tinifile.Create(gsapppath+'config.ini');
oinifileo.WriteString('MailServer','ServerName',Trim(iwedit1.Text));
oinifileo.WriteString('MailServer','UserINfo',trim(iwedit2.Text));
oinifileo.WriteString('MailServer','Userkey',Trim(iwedit3.Text));
webapplication.ShowMessage('配置信息保存成功!');
iwedit1.Text:='';
iwedit2.Text:='';
iwedit3.Text:='';
end
else
begin
webapplication.ShowMessage('请填完整的配置信息');
end;
end;
查看配置文件
procedure TformMain9.IWButton2Click(Sender: TObject);
var oinifileo:Tinifile;
begin
oinifileo:=Tinifile.Create(gsapppath+'config.ini');
iwedit1.Text:=oinifileo.ReadString('MailServer','ServerName','');
iwedit2.Text:=oinifileo.ReadString('MailServer','UserINfo','');
iwedit3.Text:=oinifileo.ReadString('MailServer','Userkey','');
end;
最后一次访问系统的时间
webapplication.LastAccess;
提示信息
webapplication.ShowMessage('请填写要发布的内容!');
发送邮件
procedure TformMain7.mailconfig;
var oinifileo:Tinifile;
begin
oinifileo:=Tinifile.Create(gsapppath+'config.ini');
idsmtp1.Host:=Trim(oinifileo.ReadString('MailServer','ServerName','mail.radiance-sh.com'));
idsmtp1.Username:=Trim(oinifileo.ReadString('MailServer','UserINfo','jordan.qiu'));
idsmtp1.Password:=Trim(oinifileo.ReadString('MailServer','Userkey','111111'));
end;
procedure TformMain7.sendmail1;
var s,s1,s2,s3,s4,m,n,ma,ad:string;
begin
s:='工号(或登陆名称):'+iwedit1.Text+' '+'姓名:'+iwedit2.Text;
ma:=Trim(iwedit5.Text)+'@radiance-sh.com';
m:='Email:'+' '+ma;
n:='您的ERP维护支持系统审核帐号已经建立,请在登陆后更改密码。具体信息如下';
s1:='您好,这是一封系统自动发送的邮件,请不要回复,如有疑问请联系235#';
s2:='系统的登陆地址为:http://172.16.5.246:8081';
s3:='当您部门的工作人员提交ERP需求申请后,系统会发邮件通知您,只要登陆系统,点击[审核系统]即可了解和审核本部门的申请信息。';
s4:='您的初始密码为:123456';
ad:=Trim(iwedit5.Text)+'@radiance-sh.com' ; //设定收件人地址
idmessage1.Clear;
//idmessage1.From.Address:=Trim('jordan.qiu@radiance-sh.com'); //发送地址
idmessage1.Recipients.EMailAddresses:=Trim(ad); //接收地址
//idmessage1.CCList.EMailAddresses:=Trim(iwdbedit6.Text)+'@radiance-sh.com'; //抄送地址
idmessage1.Subject:='ERP SUPPORT REQUISITION SYSTEM(帐号通知) '; //邮件主题
idmessage1.Body.Add(s1); //邮件正文
idmessage1.Body.Add(n);
idmessage1.Body.Add(s);
idmessage1.Body.Append(m);
idmessage1.Body.Append(s4);
idmessage1.Body.Append(s2);
idmessage1.Body.Append(s3);
try
mailconfig;
idsmtp1.Connect;
idsmtp1.Send(idmessage1);
finally
idsmtp1.Disconnect;
end;
end;
Case语句的使用
procedure TformMain5.IWButton1Click(Sender: TObject);
begin
DataModule1.ADOQ5.Close;
DataModule1.ADOQ5.SQL.Clear;
DataModule1.ADOQ5.SQL.Add('select * from ecn_base');
if iwcombobox1.Text<>'' then
begin
case iwcombobox1.ItemIndex of
0:DataModule1.ADOQ5.SQL.Add('where eno=:a');
1:DataModule1.ADOQ5.SQL.Add('where department=:a');
2:DataModule1.ADOQ5.SQL.Add('where sid=:a');
end;
DataModule1.ADOQ5.Parameters.ParamByName('a').Value:=iwedit1.Text;
end;
DataModule1.ADOQ5.Open;
end;
下载附件
procedure TformMain4.IWButton8Click(Sender: TObject); //下载附件
var
filename:string;
begin
if iwdblabel4.Caption='' then
begin
webapplication.showmessage('此申请没有相关附件!');
exit;
end
else
begin
filename:=gsapppath+'files\'+iwdblabel4.Caption;
if not fileexists(filename) then
begin
webapplication.showmessage('相关下载已删除或上传失败,请联络管理员!');
exit;
end;
webapplication.sendfile(gsapppath+'files\'+iwdblabel4.Caption,'.rar',iwdblabel4.Caption,true);//下载文件
//格式为:webapplication.sendfile(服务器端路径,文件类型,文件名,是否为附件);
end;
end;
上传动作
procedure TformMain1.attachment; //文件上传
begin
if iwfile1.Filename<>'' then
begin
filename:=gsapppath+'files\'+iwfile1.Filename;
if fileexists(filename) then
begin
webapplication.ShowMessage(format('同名文件存在请使用命名规则进行命名!',[filename]));
exit;
end;
iwfile1.SaveToFile(gsapppath+'files\'+iwfile1.Filename);
iwfile1.Caption:=extractfilename(filename);
webapplication.ShowMessage('文件上传成功!'); //测试上传用
end;
end;
Sessions的使用
usersession.ZXNAME:='';
数据分页显示
procedure TformMain3.IWButton4Click(Sender: TObject);
begin
if not DataModule1.ADOQ2.Bof then
begin
DataModule1.ADOQ2.Prior;
end
else
begin
webapplication.ShowMessage('已经是第一条记录!');
end;
end;
procedure TformMain3.IWButton5Click(Sender: TObject);
begin
if not DataModule1.ADOQ2.Eof then
begin
DataModule1.ADOQ2.Next;
end
else
begin
webapplication.ShowMessage('已经是最后一条记录!');
end;
end;
带附件发送邮件
procedure TformMain1.sendemail;
var s,m,n,k,ma,ad:string;
begin
if iwfile1.Filename<>'' then //上传动作
begin
attachment;
end;
s:='工号:'+iwedit1.Text+' '+'姓名:'+iwedit2.Text+' '+'提交了新的申请';
ma:=Trim(iwedit5.Text)+'@radiance-sh.com';
m:='Email:'+' '+ma;
n:='编号:'+iwlabel3.Caption;
k:='申请提交日期'+DataModule1.ADOQ6.FieldByName('REQUISITIONDATE').AsString;
adoq13.Close;
adoq13.SQL.Clear;
adoq13.SQL.Add('select * from ecn_user where bm=:a and qx=2');
adoq13.Parameters.ParamByName('a').Value:=Trim(iwcombobox1.Text);
adoq13.Open;
if not(adoq13.Eof) then
begin
if adoq13.FieldByName('qx').AsInteger=2 then
begin
if adoq13.FieldByName('email').AsString<>'' then
begin
ad:=Trim(adoq13.Fieldbyname('email').AsString)+'@radiance-sh.com' ; //设定收件人地址
idmessage1.Clear;
//idmessage1.From.Address:=Trim('jordan.qiu@radiance-sh.com'); //发送地址
idmessage1.Recipients.EMailAddresses:=Trim(ad); //接收地址
//idmessage1.CCList.EMailAddresses:='jordan.qiu@radiance-sh.com'; //抄送地址
idmessage1.Subject:='ERP SUPPORT REQUISITION SYSTEM '; //邮件主题
idmessage1.Body.Add(s); //邮件正文
idmessage1.Body.Append(m);
idmessage1.Body.Append(n);
idmessage1.Body.Append(k);
idmessage1.Body.Append(iwmemo1.Lines.Text);
idmessage1.Body.Append('请登陆 http://172.16.5.246:8081 进行审核');
if iwfile1.Filename<>'' then //添加附件(用户的上传附件)
begin
Tidattachment.Create(idmessage1.MessageParts,filename);
end;
try
mailserverconfig;
idsmtp1.Connect;
idsmtp1.Send(idmessage1);
//webapplication.ShowMessage('ok'); //测试是否连通使用
finally
idsmtp1.Disconnect;
end;
end;
end;
end;
end;
procedure TformMain1.mailserverconfig;
var oinifileo:Tinifile;
begin
oinifileo:=Tinifile.Create(gsapppath+'config.ini');
idsmtp1.Host:=Trim(oinifileo.ReadString('MailServer','ServerName','mail.radiance-sh.com'));
idsmtp1.Username:=Trim(oinifileo.ReadString('MailServer','UserINfo','jordan.qiu'));
idsmtp1.Password:=Trim(oinifileo.ReadString('MailServer','Userkey','111111'));
end;