Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loMailman
LOCAL loEmail
LOCAL loAccepted
LOCAL loRejected
LOCAL n
LOCAL i

lnSuccess = 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.

loMailman = CreateObject('Chilkat.MailMan')

*  Configure the SMTP server connection.
loMailman.SmtpHost = "smtp.example.com"
loMailman.SmtpPort = 465
loMailman.SmtpSsl = 1
loMailman.SmtpUsername = "user@example.com"
loMailman.SmtpPassword = "myPassword"

*  Send an email to two recipients.
loEmail = CreateObject('Chilkat.Email')
loEmail.Subject = "Test email"
loEmail.From = "alice@example.com"
loEmail.AddTo("Bob","bob@example.com")
loEmail.AddTo("Carol","carol@example.com")
loEmail.Body = "Hello!"
lnSuccess = loMailman.SendEmail(loEmail)
IF (lnSuccess = 0) THEN
    ? loMailman.LastErrorText
    RELEASE loMailman
    RELEASE loEmail
    CANCEL
ENDIF

*  Get the recipients the server accepted (rejected = 0).
loAccepted = CreateObject('Chilkat.StringTable')
loMailman.SmtpRecipientsLog(0,loAccepted)
? "Accepted recipients: " + STR(loAccepted.Count)

*  Get the recipients the server rejected (rejected = 1).
loRejected = CreateObject('Chilkat.StringTable')
loMailman.SmtpRecipientsLog(1,loRejected)
n = loRejected.Count
? "Rejected recipients: " + STR(n)

FOR i = 0 TO n - 1
    ? loRejected.StringAt(i)
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.

RELEASE loMailman
RELEASE loEmail
RELEASE loAccepted
RELEASE loRejected