自己写email发送程序出错,请高手指点(100分)

  • 主题发起人 主题发起人 jlcsx
  • 开始时间 开始时间
J

jlcsx

Unregistered / Unconfirmed
GUEST, unregistred user!
以下代码执行出错:
socket error #10053 software caused connected abort
====================================================
if not IdSMTP1.Connected then

begin
IdSMTP1.Authen
ticationType := atLogin;
IdSMTP1.Host := 'smtp.163.com';
IdSMTP1.Port := 25;
IdSMTP1.Username := 'jlcsx';
IdSMTP1.Password := '************';
IdSMTP1.Connect();
end;

那位高手有相关代码,能否email给我参考参考:
jlcsx@sina.com
qq:251500869
 
请问 Indy支持 DNS解析吗? 如果不支持, 你最好先用系统API解析出IP再连接。
 
靠,当然支持。从以前的COM组件里面抄一段
Function TKMBasic.Get_SendMail(MailFrom, MailTo, CC, BCC, Subject,
Body: OleVariant;
IsHTML: WordBool;
Charset, AttachmentFile: OleVariant;
NeedLogin: WordBool;
ServerAddress, ServerPort, ServerAccount,
ServerPassword: OleVariant): WordBool;
Var
IdMessage1: TIdMessage;
IdSMTP1: TIdSMTP;
a, b, c, d, e, f, g, h, i, j, k, l: WideString;
begin
IdSMTP1 := TIdSMTP.Create(Nil);
a := VarToWideStr(MailFrom);
b := VarToWideStr(MailTo);
c := VarToWideStr(CC);
d := VarToWideStr(BCC);
e := VarToWideStr(Subject);
f := VarToWideStr(Body);
g := VarToWideStr(Charset);
h := VarToWideStr(AttachmentFile);
i := VarToWideStr(ServerAddress);
j := VarToWideStr(ServerPort);
k := VarToWideStr(ServerAccount);
l := VarToWideStr(ServerPassword);
IdMessage1 := TIdMessage.Create(Nil);
With IdMessage1do
begin
Body.Append(f);
From.Text := a;
ReplyTo.EMailAddresses := '';
Recipients.EMailAddresses := b;
Subject := e;
Priority := TIdMessagePriority(3);
CCList.EMailAddresses := c;
BccList.EMailAddresses := d;
If IsHTML then
ContentType := 'text/html';
If g <> '' then
Charset := g;
Try
If h <> '' then
TIdAttachment.Create(IdMessage1.MessageParts, h);
Except
On E: Exceptiondo
_LastError := E.Message;
end;
end;
If NeedLogin then
IdSMTP1.Authen
ticationType := atLogin else
IdSMTP1.Authen
ticationType := atNone;
IdSMTP1.Username := k;
IdSMTP1.Password := l;
IdSMTP1.Host := i;
IdSMTP1.Port := StrToInt(j);
Try
IdSMTP1.Connect;
IdSMTP1.Send(IdMessage1);
IdSMTP1.Disconnect;
Result := True;
Except
On E: Exceptiondo
begin
Result := False;
_LastError := E.Message;
Try
IdSMTP1.Disconnect;
Except
end;
end;
end;
IdMessage1.Free;
IdSMTP1.Free;
end;
 
后退
顶部