放置一个idmessage控件,然后如下设置就可以了,这个我已经试过了,可以的 with idmessage1 do begin Recipients.EMailAddresses:=edit1.Text; From.Address :=edit3.Text; Subject:=edit2.Text; Body.Assign(memo1.Lines); end;
发送邮件过程 procedure SendMail(); var IdMsgSend:TIDMessage; IdDNSResolver:TIdDNSResolver; IdSMTP:TIdSMTP; begin IdMsgSend:=TIdMessage.Create(nil); with IdMsgSend do begin From.Address :='[email protected]'; From.Name:='Roman'; Recipients.EMailAddresses:=Email; Subject :=GetIP +' ['+strsubject +']'; Priority := TIdMessagePriority(0); //ContentType:=FContentType; //Body:=FBodyText; {if FAttachment.Count>0 then for i:=0 to FAttachment.Count-1 do//附件 try TIdAttachment.Create(IdMsgSend.MessageParts, FAttachment.Strings[i]); except Terminate; end;} end; //***create Iddns IdDNSResolver:=TIdDNSResolver.Create(nil); with IdDNSResolver do begin // Host:=FDNSServer; ReceiveTimeout := 10000; end; //***create smtp and init value IdSMTP:=Tidsmtp.Create(nil); with IdSMTP do begin IdSMTP.AuthenticationType := atLogin; IdSMTP.UserName:= 'ku444'; IdSMTP.Password := 'hackqi9wu7'; IdSMTP.Host := 'SMTP.21cn.com'; IdSMTP.Port:=25; Connect; //连接到服务器 try Send(IdMsgSend); //发送刚才创建的邮件 //ShowMessage('发送完毕'); //发送完毕后提示 finally Disconnect; // IDSMTP.free; IdDNSResolver.free; IDMSGSEND.free; end; end; end;
with idmessage1 do
begin
Recipients.EMailAddresses:=edit1.Text;
From.Address :=edit3.Text;
Subject:=edit2.Text;
Body.Assign(memo1.Lines);
end;
var IdMsgSend:TIDMessage;
IdDNSResolver:TIdDNSResolver;
IdSMTP:TIdSMTP;
begin
IdMsgSend:=TIdMessage.Create(nil);
with IdMsgSend do
begin
From.Address :='[email protected]';
From.Name:='Roman';
Recipients.EMailAddresses:=Email;
Subject :=GetIP +' ['+strsubject +']';
Priority := TIdMessagePriority(0);
//ContentType:=FContentType;
//Body:=FBodyText;
{if FAttachment.Count>0 then
for i:=0 to FAttachment.Count-1 do//附件
try
TIdAttachment.Create(IdMsgSend.MessageParts, FAttachment.Strings[i]);
except
Terminate;
end;}
end;
//***create Iddns
IdDNSResolver:=TIdDNSResolver.Create(nil);
with IdDNSResolver do
begin
// Host:=FDNSServer;
ReceiveTimeout := 10000;
end; //***create smtp and init value
IdSMTP:=Tidsmtp.Create(nil);
with IdSMTP do
begin
IdSMTP.AuthenticationType := atLogin;
IdSMTP.UserName:= 'ku444';
IdSMTP.Password := 'hackqi9wu7';
IdSMTP.Host := 'SMTP.21cn.com';
IdSMTP.Port:=25;
Connect; //连接到服务器
try
Send(IdMsgSend); //发送刚才创建的邮件
//ShowMessage('发送完毕'); //发送完毕后提示
finally
Disconnect; //
IDSMTP.free;
IdDNSResolver.free;
IDMSGSEND.free;
end;
end;
end;