如何用DELPHI2010发送带附件的邮件?
时间:2011-11-22
来源:互联网
在网上和论坛上都搜了,没有发现相关的内容,请大家赐教!
如何用DELPHI2010发送带附件的邮件
如何用DELPHI2010发送带附件的邮件
作者: jxbw197408 发布时间: 2011-11-22
该回复于2011-11-22 15:56:50被管理员删除
- 对我有用[0]
- 丢个板砖[0]
- 引用
- 举报
- 管理
- TOP
|
#2楼 得分:0回复于:2011-11-22 17:18:18
|
作者: scu96124678 发布时间: 2011-11-22
首先在uses列表中添加: IdAttachmentFile单元。
我写了一个简单的过程,代码如下:
//参数Attachment是要作为附件的文件。例如:f:\text.txt
procedure FastMail(Attachment: string);
var
FSMTP: TIdSMTP;
FMailMessage: TIdMessage;
begin
FSMTP := TIdSMTP.Create(nil);
FMailMessage := TIdMessage.Create(nil);
//为正常显示汉字设置字符集
FMailMessage.CharSet := 'gb2312';
//服务器参数
FSMTP.Host := '这里填写你的邮件服务器';
FSMTP.Username := '你的用户名';
FSMTP.Password := '你的密码';
//尝试连接服务器
try
FSMTP.Connect;
except
Exit;
end;
FMailMessage.Subject := 'Mail with Attachment';
FMailMessage.Body.Add('A demo to show how to send a mail with attachments');
FMailMessage.From.Address := '发信人地址';
FMailMessage.Recipients.EMailAddresses := '收信人地址';
//附件处理,可以连续添加多个附件
if FileExists(Attachment) then
TIdAttachmentFile.Create(FMailMessage.MessageParts, FAttachment);
//设置邮件优先级为最高
FMailMessage.Priority := mpHighest;
try
FSMTP.Send(FMailMessage);
finally
FSMTP.Disconnect;
FSMTP.Free;
FMailMessage.Free;
end;
end;
这段代码在Delphi 2010 和 XE2中皆可通过。希望对楼主有帮助。
我写了一个简单的过程,代码如下:
//参数Attachment是要作为附件的文件。例如:f:\text.txt
procedure FastMail(Attachment: string);
var
FSMTP: TIdSMTP;
FMailMessage: TIdMessage;
begin
FSMTP := TIdSMTP.Create(nil);
FMailMessage := TIdMessage.Create(nil);
//为正常显示汉字设置字符集
FMailMessage.CharSet := 'gb2312';
//服务器参数
FSMTP.Host := '这里填写你的邮件服务器';
FSMTP.Username := '你的用户名';
FSMTP.Password := '你的密码';
//尝试连接服务器
try
FSMTP.Connect;
except
Exit;
end;
FMailMessage.Subject := 'Mail with Attachment';
FMailMessage.Body.Add('A demo to show how to send a mail with attachments');
FMailMessage.From.Address := '发信人地址';
FMailMessage.Recipients.EMailAddresses := '收信人地址';
//附件处理,可以连续添加多个附件
if FileExists(Attachment) then
TIdAttachmentFile.Create(FMailMessage.MessageParts, FAttachment);
//设置邮件优先级为最高
FMailMessage.Priority := mpHighest;
try
FSMTP.Send(FMailMessage);
finally
FSMTP.Disconnect;
FSMTP.Free;
FMailMessage.Free;
end;
end;
这段代码在Delphi 2010 和 XE2中皆可通过。希望对楼主有帮助。
作者: jxbw197408 发布时间: 2011-11-22
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28