奇怪~`,发送完邮件时第一个接受人同时也收到发给第二个接受人的邮件,不解,望高手看看~代码如下:(服务器不需要验证)unit main;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,NMsmtp; function doSendEMLInfo: Boolean;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations } end;var
Form1: TForm1;implementation{$R *.dfm}function doSendEMLInfo: Boolean;
var
NMSMTP1: TNMSMTP;
DstList,AList:TStringList;
i:integer;
begin
try
NMSMTP1:=TNMSMTP.Create(Nil);
NMSMTP1.Host := 'localhost';
NMSMTP1.Port := 25;
NMSMTP1.UserID := 'komatu';
NMSMTP1.Connect;
except
ShowMessage('邮件服务器连接失败');
Result :=false;
exit;
end; //设置邮件发送方信息
NMSMTP1.PostMessage.FromAddress := '[email protected]';
NMSMTP1.PostMessage.FromName := 'komatu';
NMSMTP1.PostMessage.Date :=DateToStr(Date())+' '+TimeToStr(time());
//发送目标列表
DstList :=TStringList.Create;
DstList.Add('[email protected]');
DstList.Add('[email protected]');
//轮询发送
for i:=0 to 1 do
begin
//清空信息
NMSMTP1.PostMessage.ToAddress.Clear;
NMSMTP1.PostMessage.ToAddress.Add(DstList.Strings[i]);
//主体
AList :=TStringList.Create;
AList.Add('最近安排');
if(i>0)then
Alist.Add('more');
NMSMTP1.PostMessage.Body.Assign(AList); //发送
NMSMTP1.SendMail;
showmessage('邮件成功发送到邮箱:'+DstList.Strings[i]+'!');
Result :=True;
end;
NMSMTP1.Free;
AList.Free;
DstList.Free;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
doSendEMLInfo;
end;end.
期望结果是:
komatu,komatu1各收到一份信,现在的结果却是komatu手到两份,其中有一份是发给komatu1的.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,NMsmtp; function doSendEMLInfo: Boolean;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations } end;var
Form1: TForm1;implementation{$R *.dfm}function doSendEMLInfo: Boolean;
var
NMSMTP1: TNMSMTP;
DstList,AList:TStringList;
i:integer;
begin
try
NMSMTP1:=TNMSMTP.Create(Nil);
NMSMTP1.Host := 'localhost';
NMSMTP1.Port := 25;
NMSMTP1.UserID := 'komatu';
NMSMTP1.Connect;
except
ShowMessage('邮件服务器连接失败');
Result :=false;
exit;
end; //设置邮件发送方信息
NMSMTP1.PostMessage.FromAddress := '[email protected]';
NMSMTP1.PostMessage.FromName := 'komatu';
NMSMTP1.PostMessage.Date :=DateToStr(Date())+' '+TimeToStr(time());
//发送目标列表
DstList :=TStringList.Create;
DstList.Add('[email protected]');
DstList.Add('[email protected]');
//轮询发送
for i:=0 to 1 do
begin
//清空信息
NMSMTP1.PostMessage.ToAddress.Clear;
NMSMTP1.PostMessage.ToAddress.Add(DstList.Strings[i]);
//主体
AList :=TStringList.Create;
AList.Add('最近安排');
if(i>0)then
Alist.Add('more');
NMSMTP1.PostMessage.Body.Assign(AList); //发送
NMSMTP1.SendMail;
showmessage('邮件成功发送到邮箱:'+DstList.Strings[i]+'!');
Result :=True;
end;
NMSMTP1.Free;
AList.Free;
DstList.Free;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
doSendEMLInfo;
end;end.
期望结果是:
komatu,komatu1各收到一份信,现在的结果却是komatu手到两份,其中有一份是发给komatu1的.
N早就没用NM这个淘汰的东西了
Indy才是主流http://lysoft.7u7.net
你能给我一份发邮件的程序源码吗?
procedure TAdmMain_Form.MailTest_IdSMTP;
var
AIdSMTP:TIdSMTP;
AIdMessage: TIdMessage;
AHeadPart, ABodyPart, AFootPart: TIdText;
AttachFileName:string;
AImgPart: TIdAttachment;
AList:TStringList;
begin
try
AIdSMTP:=TIdSMTP.Create(Nil);
AIdSMTP.Host := MachineName;
AIdSMTP.Port := strtoint(DefaultMailPort);
AIdSMTP.UserID := DefaultMailUser;
AIdSMTP.Connect;
except
ShowMessage('邮件服务器连接失败');
exit;
end;
AIdMessage := TIdMessage.Create(nil);
//优先级别
AIdMessage.Priority :=mpHigh;
//AIdMessage.ContentTransferEncoding :='7bit';
//设置邮件发送方信息
AIdMessage.From.Name :=DefaultSentFromName;
AIdMessage.From.Text := DefaultSentFromAddress;
AIdMessage.Date :=Now;
//HTML格式
AIdMessage.ContentType := 'multipart/mixed';
AIdMessage.ClearBody;
AIdMessage.Subject :='测试邮件';
AIdMessage.Recipients.Clear;
AIdMessage.Recipients.EMailAddresses := trim(suiEdit_DefaultSentFromAddress.Text); //增加邮件头部内容
AList :=TStringList.Create;
AList.LoadFromFile(ACommFunc.ProgramPath+'TemPlate\EMLTemPlate\EMAIL_Image_Head.txt');
AttachFileName :=trim(AList.Strings[0]);
if(AttachFileName<>'')and(FileExists(AttachFileName))then
AServiceFunc.doloadImgIncline(AttachFileName,AIdMessage,AHeadPart,AImgPart);
AList.Clear; //形成邮件主体
AList.Add('测试邮件'); //增加主体部分内容,并保证TIdText数目必须保证大于1
ABodyPart := TIdText.Create(AIdMessage.MessageParts);
ABodyPart.ContentType := 'text/plain';
ABodyPart.Body.Text :=AList.Text; //增加邮件尾部内容
AFootPart := TIdText.Create(AIdMessage.MessageParts);
AFootPart.ContentType := 'text/html'; //如果是text/html则不显示?
AFootPart.Body.Text :=''; if(suiComboBox_IFNeedVerify.ItemIndex =0)then
begin
AIdSMTP.AuthenticationType :=atLogin;
AIdSMTP.UserId :=trim(suiEdit_DefaultMailUser.Text);
AIdSMTP.Password :=trim(suiEdit_DefaultMailPass.Text);
HaveVerifyOK :=AIdSMTP.Authenticate;
end;
if ((HaveVerifyOK ) and (suiComboBox_IFNeedVerify.ItemIndex=0))//代表认证成功了
or (suiComboBox_IFNeedVerify.ItemIndex=1)//不需要验证
then
begin
try
AIdSMTP.Send(AIdMessage);
Showmessage('邮件测试成功,并发送到'+trim(suiEdit_DefaultSentFromAddress.Text)+'!');
except
on E: Exception do
Showmessage('邮件测试失败,因为'+E.Message+'!');
end;
end
else
begin
Showmessage('邮件测试失败,请检查相关参数!');
end;
AList.Free;
AIdMessage :=Nil;
AIdSMTP :=Nil;
end;