B
baoyun
Unregistered / Unconfirmed
GUEST, unregistred user!
这是《80例上手Delphi 7编程》中的邮件群发例子,使用SMTP协议发送邮件,用了Indy系列组件中的TidMessage 和 TIdSMTP。
但是我怎么运行后不能群发?
代码如下:
procedure TForm1.sendclick(Sender: TObject);
var
i: integer;
begin
if ListBox1.Items.Count = 0 then
begin
showmessage('发送列表为空,邮件发送失败!');
exit;
end;
if mailmemo.Text = '' then
begin
showmessage('邮件内容为空!');
exit;
end;
Button1.Enabled := False;
if cb_authentication.Checked then //服务器验证
begin
IdSMTP1.AuthenticationType := atLogin;
IdSMTP1.Username := le_user.Text;
IdSMTP1.Password := le_pass.Text;
end else
begin
IdSMTP1.AuthenticationType := atNone;
end;
IdSMTP1.Host := le_smtp.Text;
IdSMTP1.Port := StrToIntDef(le_port.Text, 25); //如果转换错误默认25
IdSMTP1.Connect; //连接
try
Tag := 1; //设置中断标志
for i := 0 to ListBox1.Items.Count - 1 do
begin //循环发送
if Tag = 0 then exit; //如果中断则退出群发
SendEmail(ListBox1.Items.Strings);{SendEmail()是设置发送邮件信息的函数,另外附在下面}
IdSMTP1.Send(IdMessage1);
ListBox1.ItemIndex := i;
Application.ProcessMessages;
end;
finally
Tag := 0;
IdSMTP1.Disconnect;
Button1.Enabled := True;
end;
end;
{设置发送邮件信息的函数}
function TForm1.SendEmail(aAddr: string): boolean;
begin
IdMessage1.Body.Assign(mailmemo.Lines);
IdMessage1.From.Text := le_email.Text;
IdMessage1.ReplyTo.EMailAddresses := le_email.Text;
IdMessage1.Recipients.EMailAddresses := aAddr;
IdMessage1.Subject := le_title.Text;
end;
但是我怎么运行后不能群发?
代码如下:
procedure TForm1.sendclick(Sender: TObject);
var
i: integer;
begin
if ListBox1.Items.Count = 0 then
begin
showmessage('发送列表为空,邮件发送失败!');
exit;
end;
if mailmemo.Text = '' then
begin
showmessage('邮件内容为空!');
exit;
end;
Button1.Enabled := False;
if cb_authentication.Checked then //服务器验证
begin
IdSMTP1.AuthenticationType := atLogin;
IdSMTP1.Username := le_user.Text;
IdSMTP1.Password := le_pass.Text;
end else
begin
IdSMTP1.AuthenticationType := atNone;
end;
IdSMTP1.Host := le_smtp.Text;
IdSMTP1.Port := StrToIntDef(le_port.Text, 25); //如果转换错误默认25
IdSMTP1.Connect; //连接
try
Tag := 1; //设置中断标志
for i := 0 to ListBox1.Items.Count - 1 do
begin //循环发送
if Tag = 0 then exit; //如果中断则退出群发
SendEmail(ListBox1.Items.Strings);{SendEmail()是设置发送邮件信息的函数,另外附在下面}
IdSMTP1.Send(IdMessage1);
ListBox1.ItemIndex := i;
Application.ProcessMessages;
end;
finally
Tag := 0;
IdSMTP1.Disconnect;
Button1.Enabled := True;
end;
end;
{设置发送邮件信息的函数}
function TForm1.SendEmail(aAddr: string): boolean;
begin
IdMessage1.Body.Assign(mailmemo.Lines);
IdMessage1.From.Text := le_email.Text;
IdMessage1.ReplyTo.EMailAddresses := le_email.Text;
IdMessage1.Recipients.EMailAddresses := aAddr;
IdMessage1.Subject := le_title.Text;
end;