望各位同僚一起谈论
用Delphi 编写自动发邮件源码
达到共同进步!!
用Delphi 编写自动发邮件源码
达到共同进步!!
解决方案 »
- 新开论坛-系分之路,进者有分,大家快来呀
- 急!!!
- help~~!
- 用delphi开发创建的数据库和连接其他的数据库比如sql有什么不同?
- XML文件遍历问题
- 用intraweb开发网站好不好??
- 我的程序运行很慢怎么办?
- 能够用反射替某个对象增加属性吗?
- 请问我想控制一个外部程序的按钮,比如有一个游戏要我不停地点鼠标左键,我的鼠标左键不灵,我想用键盘上的回车键来代替鼠标左键,请问如
- ******* 小分20请教小问题**** 关于数据库中字段属性的问题,为什么字段类型是VARCHAR(4000),但是在DBGRID中的值显示却为MEMO?Room=3
- API换成DELPHI按钮启动,帮帮忙
- 更新数据库
IdSMTPClient设置好Host、Username、Password
IdMessage设置好Sender、From、ReplyTo等
IdMessage设置BccList(收件地址)、CCList(抄送地址)、Recipients(回执地址)
IdMessage加上Subject、Body、MessageParts
可以用TIdAttachment.Create(IdMessage.MessageParts, AFileName)加附件
然后使用IdSMTPClient.Send(IdMessage)就可以了
private
Zt:Integer;
procedure Sendemail;procedure TWko_Ept_Pes.Sendemail;
var
StrToMail,Strport,StrHost:string;
StrUname,StrPwd,StrFMail:string;
Ini:tinifile;
I,J:Integer;
Str:string;
tmplst:TStringList;
begin
ini:=tinifile.Create(ExtractFilePath(Application.ExeName)+'Setup.ini');
StrToMail:=ini.ReadString('Mail','tomail','');
Strport:=ini.ReadString('Mail','Port','25');
StrHost:=ini.ReadString('Mail','Host','');
StrUName:=ini.ReadString('Mail','UName','');
StrPwd:=ini.ReadString('Mail','Pwd','');
StrFMail:=ini.ReadString('Mail','fmail','');
IdSMTP1.Host:=StrHost;
IdSMTP1.Port:=strtoint(Strport);
IdSMTP1.Username:=StrUname;
IdSMTP1.Password:=StrPwd;
IdSMTP1.AuthenticationType:=atLogin;
IdMessage1.From.Address:=StrFMail;
IdMessage1.From.Name:='MES';
tmplst:=TStringList.Create;
ini.ReadSection('TMail',tmplst);
ini.Free;
IdMessage1.BccList.EMailAddresses:=tmplst.Text;
IdMessage1.Priority:=mpHigh;
if Zt=1 then IdMessage1.Subject:='MES產線異常通知:修改'+ cx_no.Text;
if Zt=2 then IdMessage1.Subject:='MES產線異常通知:新增'+ cx_no.Text;
IdMessage1.Body.Clear;
IdMessage1.Body.Append('注意:本信件為昆盈MES系統自動產生之通知信函,請不要直接回信,系統不會作任何回應!!!');
IdMessage1.Body.Append('_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _');
IdMessage1.Body.Append('--------【昆盈MES產線異常通知處理單】--------');
IdMessage1.Body.Append('編號: '+ cx_no.Text);
IdMessage1.Body.Append('工單號: '+ cx_wo.Text);
IdMessage1.Body.Append('料號: '+ cx_pn.Text);
IdMessage1.Body.Append('機種: '+ cx_model.Text);
IdMessage1.Body.Append('計劃量: ' + cx_pl.Text + '成品: '+ cx_ywcl.Text + '在製: '+ cx_wwcl.Text);
IdMessage1.Body.Append('廠別:'+ lab_cb.Caption);
IdMessage1.Body.Append('課別:'+ lab_kb.Caption);
IdMessage1.Body.Append('線別:'+ cx_xb.Text);
IdMessage1.Body.Append('異常分類:'+ cx_fl.Text); IdMessage1.Body.Append('異常現象: ');
IdMessage1.Body.Append(' '+ cx_ycxx.Text); IdMessage1.Body.Append('異常原因: ');
IdMessage1.Body.Append(' '+ cx_ycyy.Text); IdMessage1.Body.Append('處置方式: ');
IdMessage1.Body.Append(' '+ cx_tive.Text);
IdMessage1.Body.Append('接續工單: '+ cx_ect.Text);
IdMessage1.Body.Append('異常工時: '+ cx_Times.Text);
IdMessage1.Body.Append('成品: '+ cx_fg.Text);
IdMessage1.Body.Append('半成品: '+ cx_wip.Text);
IdMessage1.Body.Append('材料: '+ cx_cl.Text); IdMessage1.Body.Append('其它說明: ');
IdMessage1.Body.Append(' '+ cx_qtsm.Text); IdMessage1.Body.Append('與會人員: ');
IdMessage1.Body.Append('處理人: '+ cx_qz.Text);
IdMessage1.Body.Append('責任部門: '+ cx_zrbm.Text);
IdMessage1.Body.Append('主席: '+ cx_by.Text);
IdMessage1.Body.Append('工程經理: '+ cx_eng.Text);
IdMessage1.Body.Append('生管經理: '+ cx_pmd.Text);
IdMessage1.Body.Append('品管經理: '+ cx_qcd.Text);
IdMessage1.Body.Append('行政經理: '+ cx_add.Text);
IdMessage1.Body.Append('製造經理: '+ cx_mfd.Text);
IdMessage1.Body.Append('日期: '+ cx_dt.Text);
IdMessage1.Body.Append('_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _');
try
try
IdSMTP1.Connect;
IdSMTP1.Send(IdMessage1);
tmplst.Free;
except
Messagebox(handle,'發送郵件失敗','出錯',MB_ICONERROR+MB_OK);
end;
finally
if IdSMTP1.Connected then IdSMTP1.Disconnect;
end;
end;procedure TWko_Ept_Pes.btnSendto_mailClick(Sender: TObject);
begin
inherited;
Sendemail;
end;
uses IniFiles;