Delphi ActiveX
Delphi ActiveX
Get Accepted and Rejected SMTP Recipients
See more SMTP Examples
Demonstrates the Chilkat MailMan.SmtpRecipientsLog method, which returns the list of recipient email addresses accepted or rejected by the SMTP server during the most recent email-send operation. Pass true to get the rejected list or false to get the accepted list. This example sends a message to two recipients and reports both lists.
Background: A send to multiple recipients is not necessarily all-or-nothing: the server judges each
RCPT TO separately, so a message can be delivered to some addresses while others are refused. Inspecting these lists after a send tells you exactly who was accepted and who was not — essential for reporting partial failures accurately or flagging bad addresses in a mailing list, rather than assuming a successful send reached everyone.Chilkat Delphi ActiveX Downloads
var
success: Integer;
mailman: TChilkatMailMan;
email: TChilkatEmail;
accepted: TChilkatStringTable;
rejected: TChilkatStringTable;
n: Integer;
i: Integer;
begin
success := 0;
// Demonstrates the MailMan.SmtpRecipientsLog method, which returns the list of recipient
// email addresses accepted or rejected by the SMTP server during the most recent email-send
// operation. Pass 1 for the rejected list, or 0 for the accepted list.
mailman := TChilkatMailMan.Create(Self);
// Configure the SMTP server connection.
mailman.SmtpHost := 'smtp.example.com';
mailman.SmtpPort := 465;
mailman.SmtpSsl := 1;
mailman.SmtpUsername := 'user@example.com';
mailman.SmtpPassword := 'myPassword';
// Send an email to two recipients.
email := TChilkatEmail.Create(Self);
email.Subject := 'Test email';
email.From := 'alice@example.com';
email.AddTo('Bob','bob@example.com');
email.AddTo('Carol','carol@example.com');
email.Body := 'Hello!';
success := mailman.SendEmail(email.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(mailman.LastErrorText);
Exit;
end;
// Get the recipients the server accepted (rejected = 0).
accepted := TChilkatStringTable.Create(Self);
mailman.SmtpRecipientsLog(0,accepted.ControlInterface);
Memo1.Lines.Add('Accepted recipients: ' + IntToStr(accepted.Count));
// Get the recipients the server rejected (rejected = 1).
rejected := TChilkatStringTable.Create(Self);
mailman.SmtpRecipientsLog(1,rejected.ControlInterface);
n := rejected.Count;
Memo1.Lines.Add('Rejected recipients: ' + IntToStr(n));
for i := 0 to n - 1 do
begin
Memo1.Lines.Add(rejected.StringAt(i));
end;
// Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
// connects and authenticates -- using the property settings above -- whenever a server
// operation requires it. Calling the explicit connect/authenticate methods can still be
// helpful to determine whether a failure occurs while connecting or while authenticating.