5
51zhan.com
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TfrmMain.SendMail;
var
MxList: TStringList;
i: Integer;
QName, ThoughAddress: string;
sMX,sDomain:string;
lMX:TstringList;
FailNum,WinNum: integer;
IdSMTP1 : TIdSMTP;
IdMessage1: TIdMessage;
begin
{ 根据用户所填写的内容创建邮件 }
WinNum := 0;
FailNum := 0;
g1.MinValue := 0;
g1.MaxValue := intMailNum - 1;
g1.Visible := true;
for i:=0 to intMailNum-1do
begin
ThoughAddress := StrGrdEmail.Cells[0,i+1];
IdMessage1 := TIdMessage.Create(Application);
try
with IdMessage1do
begin
Body.Assign(mmContent.Lines);
//邮件正文
From.Address := Trim(edtFrom.Text);
//发件人地址
Recipients.EMailAddresses := ThoughAddress;//Trim(edtTo.Text);
//收件人地址
Subject := edtSubject.Text;
//邮件主题
end;
sDomain := EmailGetDomain(ThoughAddress);
if sDomain='' then
Exit;
lMX := TstringList.Create;
lMX := GetMxList('',sDomain);
try
if lMX.Count < 1 then
sMX := ''
else
sMX := lMX[0];
finally
lMX.Free;
end;
{ 发送邮件 }
IdSMTP1 := TIDSmtp.Create(Application);
try
with IdSMTP1do
begin
Host := sMX;
// 将Host赋值为目的地,这就是特快专递与普通邮件的区别
Port := 25;
// smtp服务默认的端口为25
try
Connect(5000);
//连接到服务器
except
end;
try
try
Send(IdMessage1);
//发送刚才创建的邮件
inc(WinNum);
Application.ProcessMessages;
StrGrdEmail.Cells[1,i+1] := '成功!';
lblWinNum.Caption := inttostr(WinNum);
except
inc(FailNum);
Application.ProcessMessages;
StrGrdEmail.Cells[1,i+1] := '失败!';
lblFailNum.Caption := inttostr(FailNum);
end;
finally
Disconnect;
//断开服务器连接
end;
end;
g1.Progress := i;
finally
IdSMTP1.Free;
end;
finally
IdMessage1.Free;
end;
end;
end;
var
MxList: TStringList;
i: Integer;
QName, ThoughAddress: string;
sMX,sDomain:string;
lMX:TstringList;
FailNum,WinNum: integer;
IdSMTP1 : TIdSMTP;
IdMessage1: TIdMessage;
begin
{ 根据用户所填写的内容创建邮件 }
WinNum := 0;
FailNum := 0;
g1.MinValue := 0;
g1.MaxValue := intMailNum - 1;
g1.Visible := true;
for i:=0 to intMailNum-1do
begin
ThoughAddress := StrGrdEmail.Cells[0,i+1];
IdMessage1 := TIdMessage.Create(Application);
try
with IdMessage1do
begin
Body.Assign(mmContent.Lines);
//邮件正文
From.Address := Trim(edtFrom.Text);
//发件人地址
Recipients.EMailAddresses := ThoughAddress;//Trim(edtTo.Text);
//收件人地址
Subject := edtSubject.Text;
//邮件主题
end;
sDomain := EmailGetDomain(ThoughAddress);
if sDomain='' then
Exit;
lMX := TstringList.Create;
lMX := GetMxList('',sDomain);
try
if lMX.Count < 1 then
sMX := ''
else
sMX := lMX[0];
finally
lMX.Free;
end;
{ 发送邮件 }
IdSMTP1 := TIDSmtp.Create(Application);
try
with IdSMTP1do
begin
Host := sMX;
// 将Host赋值为目的地,这就是特快专递与普通邮件的区别
Port := 25;
// smtp服务默认的端口为25
try
Connect(5000);
//连接到服务器
except
end;
try
try
Send(IdMessage1);
//发送刚才创建的邮件
inc(WinNum);
Application.ProcessMessages;
StrGrdEmail.Cells[1,i+1] := '成功!';
lblWinNum.Caption := inttostr(WinNum);
except
inc(FailNum);
Application.ProcessMessages;
StrGrdEmail.Cells[1,i+1] := '失败!';
lblFailNum.Caption := inttostr(FailNum);
end;
finally
Disconnect;
//断开服务器连接
end;
end;
g1.Progress := i;
finally
IdSMTP1.Free;
end;
finally
IdMessage1.Free;
end;
end;
end;