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]