{拉2个控件下来IdSMTP1(在Indy Clients页面), IdMessage1(在Indy Misc页面)
实现从XXOO@163.com邮箱发送带附件的邮件到10086@qq.com邮箱}
procedure TForm1.SendMail;
begin
with IdSMTP1 do
begin
Host:='smtp.163.com';
Port:=25;
Username:='XXOO';
Password:='13800138000';
AuthenticationType:=atLogin;
end;
with IdMessage1 do
begin
MessageParts.Clear;
Recipients.EMailAddresses:='10086@qq.com';
From.address:='XXOO@163.com';
Subject:='Hello';
Body.Add('Hello World');
end;
TIdAttachment.Create(IdMessage1.MessageParts,'D:\1.xls');//添加附件
try
IdSMTP1.Connect;
except on E: Exception do
begin
showmessage('连接服务嚣失败:'+E.Message);
exit;
end;
end;
try
if IdSMTP1.Authenticate then //如果AuthenticationType:=atNone; 把if IdSMTP1.Authenticate then去掉
begin
try
IdSMTP1.Send(IdMessage1);
except on E: Exception do
begin
showmessage('在发送过程中发生错误:'+E.Message);
exit;
end;
end;
showmessage('发送成功!');
end;
finally
IdSMTP1.Disconnect;
end;
end;
Delphi 发送邮件!
最新推荐文章于 2012-08-24 21:11:00 发布