+ -
当前位置:首页 → 问答吧 → 发送邮件时提示:Abstract Error

发送邮件时提示:Abstract Error

时间:2011-09-24

来源:互联网

代码如下:
procedure TetPOTPO000.OnAfterApproval;
var
  IEmailHost: TLoginEmailServer;
  IBoby: TStringList;
  IAttachmentPath: TStringList;
begin
  inherited;
  IBoby := TStringList.Create;
  IAttachmentPath := TStringList.Create;
  try
  IEmailHost.SMTPHost := '192.168.16.12';
  IEmailHost.SMTPPort := 25;
  IEmailHost.Username := 'it-email';
  IEmailHost.Password := '888898';
  //IEmailHost.SmtpAuthType := 0;
  IBoby.Add('PO在附件中');
  IAttachmentPath.Add('..\Temp.pdf');
  SendEmail(IEmailHost,'it-email','it-email2','','Test PO审核后自动发的邮件',IBoby,IAttachmentPath,'Plain');
  DeleteFile('..\Temp.pdf');
  finally
  IBoby.Free;
  IAttachmentPath.Free;
  end;


调用SendEmail的代码如下:

function SendEmail(poSMTPServer:TLoginEmailServer; psFromEmial, psToEmail, CCToEmail, psSubject:string; poBody, poAttachmentPath :TStringList;
  psContentType:string):Integer;
var
  loIdMsgSend: TIdMessage;
  loSMTP: TIdSMTP;
  MailFile : TIdAttachment;
  i:integer;
begin
  Result:=3;
  loIdMsgSend:=nil;
  loSMTP:=nil;
  try
  loIdMsgSend:=TIdMessage.Create(nil);
  loSMTP:=TIdSMTP.Create(nil);
  //------邮件信息
  with loIdMsgSend do
  begin
  ContentType := psContentType; //发送邮件的格式 'text/plain'
  From.Text := psFromEmial;
  ReplyTo.EMailAddresses := psFromEmial; //发件邮箱
  Recipients.EMailAddresses := psToEmail; //收件邮箱
  CCList.EMailAddresses := CCToEmail; //抄送邮箱
  Subject := psSubject; //主题
  Priority := mpHigh;
  ReceiptRecipient.Text := '';
  Body.Assign(poBody); //邮件内容
  if Assigned(poAttachmentPath) then //附件
  begin 
  for i := 0 to poAttachmentPath.Count-1 do
  begin
  MailFile := TIdAttachment.Create(loIdMsgSend.MessageParts);
  MailFile.FileName := poAttachmentPath.Strings[i] ;
  end;
  end;
  end;
  //发展送
  with loSMTP do
  begin
  AuthType := atDefault;
  ReadTimeout := 10000;
  Host :=poSMTPServer.SMTPHost;
  Port := poSMTPServer.SMTPPort;
  {if poSMTPServer.SmtpAuthType=1 then
  AuthType := atLogin
  else
  AuthType := atNone;}
  Username := poSMTPServer.Username;
  Password := poSMTPServer.Password;
  try
  Connect;
  try
  Send(loIdMsgSend);//执行到这里就不成功,提示:Abstract Error。
  except on E:Exception do
  ShowMessage(DispString('Email send fail: ','邮件发送失败: ')+ E.Message);
  end;
  except
  result:=2; 
  exit; 
  end; 
  Result:=0;
  end;
  finally 
  loIdMsgSend.Free;
  loSMTP.Free;
  end; 
end;


本人结贴勤快,保证一周内结贴给分。

作者: liw125008   发布时间: 2011-09-24

抽象错误的原因是你定义了抽象方法,而没有子类实现。
或者是使用的时候,定义变量的时候,使用的时祖先类,而实现的时候也使用了祖先类。祖先类中有抽象方法。
解决方式是使用这个祖先类的子类就可以了。

作者: SmallHand   发布时间: 2011-09-25