Error with SMTP

Giganews Newsgroups
Subject: Error with SMTP
Posted by:  Brad (Bradl…@telus.net)
Date: Sat, 31 Dec 2005

Hello,

I have a small problem when using Indy to send an email.  When I try to
send an email - testing the code on my machine - I get an error

Response Received is: 554  We do not accept messages with no From To or
Subject headers

This is the error reported by McAfee Virus Scan.  But I have clients
that just don't get annything.  The program completes - but they get no
message of any sort - and no email ever reaches the destination address.
I am guessing that they are getting the same problem - but have no way
of capturing it.

I get this problem when I send the email - it never arrives (I send it
to myself) - but I get the message above.  It would seem that I missing
a header of some sort - but I don't know what?

I have included the code below - that I am using.  It seems to fairly
simple.  Does anyone have an idea of what I am doing wrong?

news.atozedsoftware.com

--

G. Bradley MacDonald
bradley_AT_telus_DOT_net

//----------------------------------------------------------------------
//
//----------------------------------------------------------------------
procedure SendEmailViaSMTP(Const ToEmail      :String;
                          Const FromEmail    :String;
                          Const BodyText      :String;
                          Const SubjectText  :String;
                          Const ServerAddress :String;
                          Const UserId        :String;
                          Const Password      :String;
                          Const FileName      :String
                          );
Var
  Smtp  :TIdSMTP;
  MSG    :TIdMessage;
begin

  Smtp := TIdSmtp.Create(Nil);
  Msg  := TIdMessage.Create(Nil);
  // Now this is where we get things done.
  Try
    If (FileName <> '') then Begin
      TIdAttachmentFile.Create(Msg.MessageParts, FileName);
    end;

    with Msg do
    begin
      Body.Add(BodyText);
      From.Text                := FromEmail;
      Recipients.EMailAddresses := ToEmail;
      Subject                  := SubjectText;
      Priority                  := mpNormal;
      CCList.EMailAddresses    := '';
      BccList.EMailAddresses    := '';
      ReceiptRecipient.Text    := '';
    end;

    {authentication settings}
    SMTP.AuthType            := atNone;
    SMTP.UserName            := UserId;
    SMTP.Password            := Password;

    {General setup}
    SMTP.Host := ServerAddress;
    SMTP.Port := 25;

    {now we send the message}
    Try
      SMTP.Connect;
      try
        SMTP.Send(Msg);
      finally
        SMTP.Disconnect;
      end;  // Try..Finally
    Except
      on E: Exception do Begin
        ShowMessage('Error Sending SMTP eMail'
                  + #13#10 + #13#10
                  + 'Make sure this machine is connected to the
Internet.'
                  + #13#10 + #13#10
                  + 'Original Message: ' + E.Message
                  );
      End; // On E
    End;  // Try..Except
  Finally
    Smtp.Free;
    Msg.Free;
  End;
end; // SMTP Mail

Replies