Delphi中发送邮件的代码,不完全参考
2006-07-02 10:01
633 查看
indy10组件的 发送邮件代码,不完全
[本文由iuprg 发表]
[http://www.newsoftstudio.com]
====================================
我的发送代码,仅供参考:
...
...
SMTP.Username := SmtpServerUser;
SMTP.Password := SmtpServerpassword ;
SMTP.Host := SmtpServerName;
case SmtpAuthType of
0: SMTP.Authtype :=atdefault ;
1:
SMTP.Authtype :=atNone ;
2:
SMTP.Authtype :=atSASL ;
end;
SMTP.Port := SmtpServerPort;
// 'IdMsgSend:tidMsgsend
with IdMsgSend do
begin
Clear;
Priority := TIdMessagePriority(mpNormal); { Message Priority }
From.Address:= UserEmail;
Subject := trim(dbeditex3.Text) ; { Subject: header }
Recipients.EMailAddresses := trim(dbeditex1.Text) ; { To: header }
Body.Clear;
Body.Add(dbmemo1.Text);
/// 附件 :
for i:=0 to listview2.Items.Count -1 do
begin
TIdAttachmentFile.Create(IdMsgSend.MessageParts,
listview2.Items[i].SubItems.Strings[1]);
// 9.0版本 TIdAttachment.Create(IdMsgSend.MessageParts,
// listview2.Items[i].SubItems.Strings[1]);
//这里是indy 10组件
end;
if chkReturnReciept.Checked then
begin {We set the recipient to the From E-Mail address }
ReceiptRecipient.Text := From.Text;
end
else
begin {indicate that there is no receipt recipiant}
ReceiptRecipient.Text := '';
end;
end; // idsendmsg
{authentication settings}
//[本文由iuprg 发表]
//[http://www.newsoftstudio.com]
try
if not smtp.Connected then
SMTP.Connect;
/// 开始批量发送
if radiobutton2.Checked then
begin
gressbar(listview1.Items.Count,'正在发邮件...');
IdMsgSend.Recipients.EMailAddresses :=
listview1.Items[i].SubItems.strings[0];
try
if not smtp.Connected then
SMTP.Connect;
try
SMTP.Send(IdMsgSend);
finally
smtp.Disconnect;
end; // 每次发送必须建立一次连接,因为 有的 mail系统会限制一次连接
// 只能发送 2封邮件,而会提示“too many letters during this connection”
except
if showmess(2,1,'往'+listview1.Items[i].SubItems.strings[0]+'发送邮件不成功!请检查输入的邮件地址是否正确/网络连接是否正常,您要继续么?')=1 then
begin
if smtp.Connected then
SMTP.disConnect;
break;
end;
end;
gresspos(i);
self.Caption:='发送完毕';
gressrelease;
end;
if radiobutton1.Checked then
begin
gressbar(listview1.Items.Count,'正在发送邮件...');
if smtp.Connected then
SMTP.Send(IdMsgSend);
gresspos(10);
gressrelease;
end;
savemail('1'); // 保存 邮件,
if smtp.Connected then
SMTP.Disconnect;
speedbutton2.Enabled :=false;
showmess(0,9,'邮件发送成功。');
except
datamd.adoq_mail.cancel;
gressrelease;
if smtp.Connected then
SMTP.Disconnect;
showmess(2,9,'邮件发送不成功!');
end
[本文由iuprg 发表]
2006-7-2
[http://www.newsoftstudio.com]
[本文由iuprg 发表]
[http://www.newsoftstudio.com]
====================================
我的发送代码,仅供参考:
...
...
SMTP.Username := SmtpServerUser;
SMTP.Password := SmtpServerpassword ;
SMTP.Host := SmtpServerName;
case SmtpAuthType of
0: SMTP.Authtype :=atdefault ;
1:
SMTP.Authtype :=atNone ;
2:
SMTP.Authtype :=atSASL ;
end;
SMTP.Port := SmtpServerPort;
// 'IdMsgSend:tidMsgsend
with IdMsgSend do
begin
Clear;
Priority := TIdMessagePriority(mpNormal); { Message Priority }
From.Address:= UserEmail;
Subject := trim(dbeditex3.Text) ; { Subject: header }
Recipients.EMailAddresses := trim(dbeditex1.Text) ; { To: header }
Body.Clear;
Body.Add(dbmemo1.Text);
/// 附件 :
for i:=0 to listview2.Items.Count -1 do
begin
TIdAttachmentFile.Create(IdMsgSend.MessageParts,
listview2.Items[i].SubItems.Strings[1]);
// 9.0版本 TIdAttachment.Create(IdMsgSend.MessageParts,
// listview2.Items[i].SubItems.Strings[1]);
//这里是indy 10组件
end;
if chkReturnReciept.Checked then
begin {We set the recipient to the From E-Mail address }
ReceiptRecipient.Text := From.Text;
end
else
begin {indicate that there is no receipt recipiant}
ReceiptRecipient.Text := '';
end;
end; // idsendmsg
{authentication settings}
//[本文由iuprg 发表]
//[http://www.newsoftstudio.com]
try
if not smtp.Connected then
SMTP.Connect;
/// 开始批量发送
if radiobutton2.Checked then
begin
gressbar(listview1.Items.Count,'正在发邮件...');
IdMsgSend.Recipients.EMailAddresses :=
listview1.Items[i].SubItems.strings[0];
try
if not smtp.Connected then
SMTP.Connect;
try
SMTP.Send(IdMsgSend);
finally
smtp.Disconnect;
end; // 每次发送必须建立一次连接,因为 有的 mail系统会限制一次连接
// 只能发送 2封邮件,而会提示“too many letters during this connection”
except
if showmess(2,1,'往'+listview1.Items[i].SubItems.strings[0]+'发送邮件不成功!请检查输入的邮件地址是否正确/网络连接是否正常,您要继续么?')=1 then
begin
if smtp.Connected then
SMTP.disConnect;
break;
end;
end;
gresspos(i);
self.Caption:='发送完毕';
gressrelease;
end;
if radiobutton1.Checked then
begin
gressbar(listview1.Items.Count,'正在发送邮件...');
if smtp.Connected then
SMTP.Send(IdMsgSend);
gresspos(10);
gressrelease;
end;
savemail('1'); // 保存 邮件,
if smtp.Connected then
SMTP.Disconnect;
speedbutton2.Enabled :=false;
showmess(0,9,'邮件发送成功。');
except
datamd.adoq_mail.cancel;
gressrelease;
if smtp.Connected then
SMTP.Disconnect;
showmess(2,9,'邮件发送不成功!');
end
[本文由iuprg 发表]
2006-7-2
[http://www.newsoftstudio.com]
相关文章推荐
- Delphi通过IdSmtp发送邮件的简单代码
- javamail 邮件发送参考代码
- delphi发送邮件代码
- c#语言邮件发送参考代码
- delphi发送邮件代码
- C# 发送邮件 参考代码
- 发送邮件的方式源代码可参考如下代码
- 关于用Java实现发送邮件(部分代码参考网络来源)
- 使用phantomjs实现highcharts等报表通过邮件发送(本文仅提供完整解决方案和实现思路,完全照搬不去整理代码无法马上得到效果)
- C#发送邮件代码
- 使用JAVA 代码发送邮件
- 使用PHPmailer发送邮件的详细代码
- JMail 参考接收发送邮件解决方案
- asp.net 邮件发送,C#代码
- 简易发送邮件代码
- 程序异常退出时发送邮件报告的代码
- ASP.net 2.0发送邮件实例,本人已经测试通过,贴出代码
- JAVA代码发送邮件示例和解释
- 利用outlook发送邮件的代码,其实就一句话,哈哈~~
- C# .NET 发送邮件 代码