DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMailman
Variant vEmail
Handle hoEmail
Variant vBadAddrs
Handle hoBadAddrs
Integer n
Integer i
String sTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatMailMan)) To hoMailman
If (Not(IsComObjectCreated(hoMailman))) Begin
Send CreateComObject of hoMailman
End
// Configure the SMTP server connection.
Set ComSmtpHost Of hoMailman To "smtp.example.com"
Set ComSmtpPort Of hoMailman To 465
Set ComSmtpSsl Of hoMailman To True
Set ComSmtpUsername Of hoMailman To "user@example.com"
Set ComSmtpPassword Of hoMailman To "myPassword"
// Build an email with the recipients to verify.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Recipient check"
Set ComFrom Of hoEmail To "alice@example.com"
Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
Get ComAddTo Of hoEmail "Nobody" "nobody@example.com" To iSuccess
// Ask the server which recipients it will accept. Rejected addresses are returned.
Get Create (RefClass(cComCkStringArray)) To hoBadAddrs
If (Not(IsComObjectCreated(hoBadAddrs))) Begin
Send CreateComObject of hoBadAddrs
End
Get pvComObject of hoEmail to vEmail
Get pvComObject of hoBadAddrs to vBadAddrs
Get ComVerifyRecips Of hoMailman vEmail vBadAddrs To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComCount Of hoBadAddrs To n
Showln "Rejected recipients: " n
For i From 0 To (n - 1)
Get ComGetString Of hoBadAddrs i To sTemp1
Showln sTemp1
Loop
// 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.
End_Procedure