Sample code for 30+ languages & platforms
AutoIt

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 AutoIt Downloads

AutoIt
Local $bSuccess = False

;  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 True for the rejected list, or False for the accepted list.

$oMailman = ObjCreate("Chilkat.MailMan")

;  Configure the SMTP server connection.
$oMailman.SmtpHost = "smtp.example.com"
$oMailman.SmtpPort = 465
$oMailman.SmtpSsl = True
$oMailman.SmtpUsername = "user@example.com"
$oMailman.SmtpPassword = "myPassword"

;  Send an email to two recipients.
$oEmail = ObjCreate("Chilkat.Email")
$oEmail.Subject = "Test email"
$oEmail.From = "alice@example.com"
$oEmail.AddTo("Bob","bob@example.com")
$oEmail.AddTo("Carol","carol@example.com")
$oEmail.Body = "Hello!"
$bSuccess = $oMailman.SendEmail($oEmail)
If ($bSuccess = False) Then
    ConsoleWrite($oMailman.LastErrorText & @CRLF)
    Exit
EndIf

;  Get the recipients the server accepted (rejected = False).
$oAccepted = ObjCreate("Chilkat.StringTable")
$oMailman.SmtpRecipientsLog False,$oAccepted
ConsoleWrite("Accepted recipients: " & $oAccepted.Count & @CRLF)

;  Get the recipients the server rejected (rejected = True).
$oRejected = ObjCreate("Chilkat.StringTable")
$oMailman.SmtpRecipientsLog True,$oRejected
Local $iN = $oRejected.Count
ConsoleWrite("Rejected recipients: " & $iN & @CRLF)
Local $i
For $i = 0 To $iN - 1
    ConsoleWrite($oRejected.StringAt($i) & @CRLF)
Next

;  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.