SMTP Message Delivery - Multiple Recipients

Giganews Newsgroups
Subject: SMTP Message Delivery - Multiple Recipients
Posted by:  Pierre Roux (pier…@infofx.co.za)
Date: Wed, 5 May 2004

The Problem:
E-Mail with multiple recipients gets delivered multiple times by the
destination server, not only once for the recipient that is configured on
the server.

The Question:
How do I get the destination server to keep one copy only for it's intented
recipient, and not forward the message to everybody?

The Code:
function TSMTPSend.SendEMail(sHostName: String; var DNSServers:
TStringList): Boolean;
var
  sDomainPart    : String;
  iMXCount      : Integer;
begin
  sDomainPart := Copy(sHostName, Pos('@', sHostName)+1,Length(sHostName));

  if GetMXRecords(sDomainPart, DNSServers, MailServers) then
    begin
    iMXCount  := 0;
    Result    := False;

    While (iMXCount < MailServers.Count) and not Result do
        begin
        SMTPClient.Host  := Copy(MailServers.Strings[iMXCount], Pos(',',
MailServers.Strings[iMXCount])+1,Length(MailServers.Strings[iMXCount]));
        try
        SMTPClient.Connect;
        SMTPClient.Send(EMail);
        SMTPClient.Disconnect;

        Result := True;

        except

        Result := False;
        Inc(iMXCount);

        end;

        end;
    end
  else
    begin
    //DNS Failed
    Result := False;
    end;

end;

Replies