PowerBuilder
PowerBuilder
Verify Email Recipients Without Sending
See more SMTP Examples
Demonstrates the Chilkat MailMan.VerifyRecips method, which begins the SMTP send process for an email, sends the recipient addresses to the SMTP server, and then aborts before sending the message content. Recipient addresses rejected by the server are returned in the StringArray. This example checks two recipients and lists any that were rejected.
Background: During an SMTP transaction each recipient is offered with a
RCPT TO command, and the server accepts or rejects it before any message content is transferred. VerifyRecips exploits that: it runs the transaction just far enough to collect those verdicts, then aborts — letting you validate an address list without actually delivering mail. Note that many servers accept everything at this stage and bounce later, so a clean result is not a guarantee of deliverability.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Email
oleobject loo_BadAddrs
integer n
integer i
li_Success = 0
// Demonstrates the MailMan.VerifyRecips method, which begins the SMTP send process for an
// email, sends the recipient addresses to the SMTP server, and then aborts before sending
// the message content. Recipient addresses rejected by the server are returned in the
// StringArray.
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"
// Build an email with the recipients to verify.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
loo_Email.Subject = "Recipient check"
loo_Email.From = "alice@example.com"
loo_Email.AddTo("Bob","bob@example.com")
loo_Email.AddTo("Nobody","nobody@example.com")
// Ask the server which recipients it will accept. Rejected addresses are returned.
loo_BadAddrs = create oleobject
li_rc = loo_BadAddrs.ConnectToNewObject("Chilkat.StringArray")
li_Success = loo_Mailman.VerifyRecips(loo_Email,loo_BadAddrs)
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
destroy loo_Email
destroy loo_BadAddrs
return
end if
n = loo_BadAddrs.Count
Write-Debug "Rejected recipients: " + string(n)
for i = 0 to n - 1
Write-Debug loo_BadAddrs.GetString(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_BadAddrs