delphi发送邮件代码
来源:互联网 发布:淘宝爆款图片大全 编辑:程序博客网 时间:2024/05/08 23:11
procedure TForm1.Button1Click(Sender: TObject);
begin
try
IdSMTP1.AuthenticationType:=atLogin; //设置登陆类型
IdSMTP1.Username:=Edit1.Text; //设置登陆帐号
IdSMTP1.Password:=Edit2.Text; //设置登陆密码
IdSMTP1.Host:=Edit3.Text; //设置SMTP地址
IdSMTP1.Port:=strtoint(Edit4.Text); //设置端口 必须转化为整型
IdSMTP1.Connect; //开始连接服务器
except
Showmessage(’连接失败,请重试!’);
Exit; //连接失败 的话 退出该执行过程
end;
IdMessage1.Body.Clear; //先清空上次发送的内容
IdMessage1.Subject:=Edit5.Text; //设置邮件发送的标题
IdMessage1.Body.Assign(Memo1.Lines); //设置邮件发送的主体
IdMessage1.From.Address:=Edit6.Text; //设置邮件的发件人 也就是说该邮件来自什么地方
IdMessage1.Recipients.EMailAddresses:=Edit7.Text; //收件人的地址
try
idSMTP1.Send(IdMessage1);
Showmessage(’邮件发送成功!’);
except
Showmessage(’邮件发送失败!’);
end;
end;
或者:
我写了一个发邮件的函数,包你满意
type
TLoginEmailServer=record
SMTPHost:string;
SMTPPort:integer;
Username:string;
Password:string;
SmtpAuthType:integer;
end;
function SendEmail(poSMTPServer:TLoginEmailServer;poBody:Tstrings;psFromEmial,
psToEmail,psSubject:string;psContentType:string;
CCToEmail:string;poAttachmentPath:TStrings):integer;
var
loIdMsgSend: TIdMessage;
loSMTP: TIdSMTP;
i:integer;
begin
Result:=3;
loIdMsgSend:=nil;
loSMTP:=nil;
try
loIdMsgSend:=TIdMessage.Create(nil);
loSMTP:=TIdSMTP.Create(nil);
with loIdMsgSend do
begin
ContentType:=psContentType;
From.Text := psFromEmial;
ReplyTo.EMailAddresses := psFromEmial;
Recipients.EMailAddresses := psToEmail;
CCList.EMailAddresses:=CCToEmail;
Subject := psSubject;
Priority := mpHigh;
ReceiptRecipient.Text := ’’;
Body.Assign(poBody);
if Assigned(poAttachmentPath) then
begin
for i := 0 to poAttachmentPath.Count-1 do
begin
TIdAttachment.Creat(loIdMsgSend.MessageParts,poAttachmentPath.Strings[i]);
end;
end;
end;
with loSMTP do
begin
Host :=poSMTPServer.SMTPHost;
Port := poSMTPServer.SMTPPort;
if poSMTPServer.SmtpAuthType=1 then
AuthenticationType:=atLogin
else
AuthenticationType:=atNone;
Username := poSMTPServer.Username;
Password := poSMTPServer.Password;
try
Connect;
Send(loIdMsgSend);
except
result:=2;
exit;
end;
Result:=0;
finally
loIdMsgSend.Free;
loSMTP.Free;
end;
end;
begin
try
IdSMTP1.AuthenticationType:=atLogin; //设置登陆类型
IdSMTP1.Username:=Edit1.Text; //设置登陆帐号
IdSMTP1.Password:=Edit2.Text; //设置登陆密码
IdSMTP1.Host:=Edit3.Text; //设置SMTP地址
IdSMTP1.Port:=strtoint(Edit4.Text); //设置端口 必须转化为整型
IdSMTP1.Connect; //开始连接服务器
except
Showmessage(’连接失败,请重试!’);
Exit; //连接失败 的话 退出该执行过程
end;
IdMessage1.Body.Clear; //先清空上次发送的内容
IdMessage1.Subject:=Edit5.Text; //设置邮件发送的标题
IdMessage1.Body.Assign(Memo1.Lines); //设置邮件发送的主体
IdMessage1.From.Address:=Edit6.Text; //设置邮件的发件人 也就是说该邮件来自什么地方
IdMessage1.Recipients.EMailAddresses:=Edit7.Text; //收件人的地址
try
idSMTP1.Send(IdMessage1);
Showmessage(’邮件发送成功!’);
except
Showmessage(’邮件发送失败!’);
end;
end;
或者:
我写了一个发邮件的函数,包你满意
type
TLoginEmailServer=record
SMTPHost:string;
SMTPPort:integer;
Username:string;
Password:string;
SmtpAuthType:integer;
end;
function SendEmail(poSMTPServer:TLoginEmailServer;poBody:Tstrings;psFromEmial,
psToEmail,psSubject:string;psContentType:string;
CCToEmail:string;poAttachmentPath:TStrings):integer;
var
loIdMsgSend: TIdMessage;
loSMTP: TIdSMTP;
i:integer;
begin
Result:=3;
loIdMsgSend:=nil;
loSMTP:=nil;
try
loIdMsgSend:=TIdMessage.Create(nil);
loSMTP:=TIdSMTP.Create(nil);
with loIdMsgSend do
begin
ContentType:=psContentType;
From.Text := psFromEmial;
ReplyTo.EMailAddresses := psFromEmial;
Recipients.EMailAddresses := psToEmail;
CCList.EMailAddresses:=CCToEmail;
Subject := psSubject;
Priority := mpHigh;
ReceiptRecipient.Text := ’’;
Body.Assign(poBody);
if Assigned(poAttachmentPath) then
begin
for i := 0 to poAttachmentPath.Count-1 do
begin
TIdAttachment.Creat(loIdMsgSend.MessageParts,poAttachmentPath.Strings[i]);
end;
end;
end;
with loSMTP do
begin
Host :=poSMTPServer.SMTPHost;
Port := poSMTPServer.SMTPPort;
if poSMTPServer.SmtpAuthType=1 then
AuthenticationType:=atLogin
else
AuthenticationType:=atNone;
Username := poSMTPServer.Username;
Password := poSMTPServer.Password;
try
Connect;
Send(loIdMsgSend);
except
result:=2;
exit;
end;
Result:=0;
finally
loIdMsgSend.Free;
loSMTP.Free;
end;
end;
- delphi发送邮件代码
- delphi发送邮件代码
- 实现邮件发送(delphi)
- Delphi发送邮件
- delphi outlook发送邮件
- delphi发送网页邮件
- delphi发送邮件
- delphi发送邮件程序
- delphi邮件定时发送
- Delphi 发送邮件!
- Delphi发送邮件...
- Delphi中发送邮件的代码,不完全参考
- Delphi通过IdSmtp发送邮件的简单代码
- delphi中发送html邮件
- delphi 简单的发送邮件
- JMail发送邮件代码
- .net 发送邮件代码
- vs2005 邮件发送代码
- 修改MYSQL数据库,数据表,字段的编码(解决JSP乱码)
- vss使用
- Delphi日期函数
- 靓,没有你的日子,我真的好孤单
- Jakarta Commnos lang学习(5)——Validate
- delphi发送邮件代码
- DELPHI域名解析为IP地址
- delphi电子邮件收发编程讲解与实例
- 简单算法考试
- 关于2个int变量交换的问题
- 关于新技术的一点看法
- POSTSQL
- 在VC6的工程中加入播放xm音乐的功能
- 教你27招,让你在社交,职场上人人对你刮目相看