IDSMTP - problems sending email

Giganews Newsgroups
Subject: IDSMTP - problems sending email
Posted by:  Mark Williams (mark@{removethis}skwirel.com)
Date: Wed, 22 Apr 2009

I am having various problems sending smtp emails. I have posted my code
below.

The errors are as follows:

1 If there are any attachments then I get an smtp error 354 "OK Send data
with <CRLF>.<CRLF>"

2 If there are no attachments I do not get this error. However, I am setting
the body of the email from a richedit and only the last line gets added to
the body text. I have tried body.assign(richedit1.lines) and I have also
tried the old fashion way of IDMessage1.body.assign(richedit1.lines) and
various variations thereon.

I am using an older indy 10 snapshot (which may be the cause of the issue
but I cannot install the latest snapshot and have posted separately on this.

Thanks for any help.

procedure TfrmEmailClient.A_SendExecute(Sender: TObject);
  var i:integer;
  attList:TStringList;
  s:string;
  TextPart:TIdText;

begin
screen.cursor:=crHourGlass;
try
    IDMessage1.Clear;
  IDMessage1.subject:=eSubject.Text;

  TextPart := TIdText.Create(IDMessage1.MessageParts, nil);
  TextPart.ContentType := 'multipart/alternative';
  TextPart.ParentPart := -1;

  TextPart := TIdText.Create(IDMessage1.MessageParts, nil);
  TextPart.ContentType := 'text/plain';
  for i:=0 to RichEdit1.lines.count-1 do
    TextPart.Body.Add(RichEdit1.Lines[i]);
  TextPart.ParentPart := 0;

  idMessage1.From.text:=cbEmailAccounts.text;
  idmessage1.Sender.text:=cbEmailAccounts.text;

  with IDMessage1.Recipients do
    Address:=eTo.text;

  for i:=0 to AttachList.count-1 do
    with TIDAttachmentFile.Create(IDMessage1.MessageParts) do
      filename:=AttachList[i];

  try
    IdSmtp1.Connect;

  except
        MessageBox(Handle, PChar('Error connecting to smtp server:
'+InttoStr(IDSmtp1.LastCmdResult.NumericCode)+' -
'+IDSMTP1.LastCmdResult.Text.Text), PChar('Email Error'), MB_OK or
MB_ICONERROR or MB_APPLMODAL);
      exit;
end;

  try
    idsmtp1.Send(idMessage1);
  except
          MessageBox(Handle, PChar('Error sending email:
'+InttoStr(IDSmtp1.LastCmdResult.NumericCode)+' -
'+IDSMtp1.LastCmdResult.Text.Text), PChar('Email Error'), MB_OK or
MB_ICONERROR or MB_APPLMODAL);
        exit;
end;

  try
    if idSMTP1.Connected then
      idSMTP1.Disconnect;
  except end;

finally
  screen.cursor:=crDefault;
end;
end;

Replies