Sample code for 30+ languages & platforms
Visual Basic 6.0

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 Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
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.

Dim mailman As New ChilkatMailMan

'  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.
Dim email As New ChilkatEmail
email.Subject = "Test email"
email.From = "alice@example.com"
success = email.AddTo("Bob","bob@example.com")
success = email.AddTo("Carol","carol@example.com")
email.Body = "Hello!"
success = mailman.SendEmail(email)
If (success = 0) Then
    Debug.Print mailman.LastErrorText
    Exit Sub
End If

'  Get the recipients the server accepted (rejected = 0).
Dim accepted As New ChilkatStringTable
mailman.SmtpRecipientsLog 0,accepted
Debug.Print "Accepted recipients: " & accepted.Count

'  Get the recipients the server rejected (rejected = 1).
Dim rejected As New ChilkatStringTable
mailman.SmtpRecipientsLog 1,rejected
Dim n As Long
n = rejected.Count
Debug.Print "Rejected recipients: " & n
Dim i As Long
For i = 0 To n - 1
    Debug.Print rejected.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.