PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Email
oleobject loo_Accepted
oleobject loo_Rejected
integer n
integer i
li_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.
loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
destroy loo_Mailman
MessageBox("Error","Connecting to COM object failed")
return
end if
// Configure the SMTP server connection.
loo_Mailman.SmtpHost = "smtp.example.com"
loo_Mailman.SmtpPort = 465
loo_Mailman.SmtpSsl = 1
loo_Mailman.SmtpUsername = "user@example.com"
loo_Mailman.SmtpPassword = "myPassword"
// Send an email to two recipients.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
loo_Email.Subject = "Test email"
loo_Email.From = "alice@example.com"
loo_Email.AddTo("Bob","bob@example.com")
loo_Email.AddTo("Carol","carol@example.com")
loo_Email.Body = "Hello!"
li_Success = loo_Mailman.SendEmail(loo_Email)
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
destroy loo_Email
return
end if
// Get the recipients the server accepted (rejected = 0).
loo_Accepted = create oleobject
li_rc = loo_Accepted.ConnectToNewObject("Chilkat.StringTable")
loo_Mailman.SmtpRecipientsLog(0,loo_Accepted)
Write-Debug "Accepted recipients: " + string(loo_Accepted.Count)
// Get the recipients the server rejected (rejected = 1).
loo_Rejected = create oleobject
li_rc = loo_Rejected.ConnectToNewObject("Chilkat.StringTable")
loo_Mailman.SmtpRecipientsLog(1,loo_Rejected)
n = loo_Rejected.Count
Write-Debug "Rejected recipients: " + string(n)
for i = 0 to n - 1
Write-Debug loo_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.
destroy loo_Mailman
destroy loo_Email
destroy loo_Accepted
destroy loo_Rejected