PureBasic
PureBasic
Verify Email Recipients
A way to possibly determine valid/invalid email addresses. I would recommend being very careful about doing this because your IP address may be flagged as a potential spammer by the mail server (because you are probing for valid/invalid email addresses). This Chilkat functionality existed for many years, before this kind of activity became a problem. The functionality remains only because it is useful for some to test with their own SMTP servers.Chilkat PureBasic Downloads
IncludeFile "CkStringArray.pb"
IncludeFile "CkEmail.pb"
IncludeFile "CkMailMan.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
mailman.i = CkMailMan::ckCreate()
If mailman.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; SMTP connection settings...
CkMailMan::setCkSmtpHost(mailman, "smtp.example.com")
CkMailMan::setCkSmtpUsername(mailman, "MY_SMTP_USERNAME")
CkMailMan::setCkSmtpPassword(mailman, "MY_SMTP_PASSWORD")
CkMailMan::setCkSmtpSsl(mailman, 1)
CkMailMan::setCkSmtpPort(mailman, 465)
; Create a new email object
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkSubject(email, "This is a test")
CkEmail::setCkBody(email, "This is a test")
CkEmail::setCkFrom(email, "myemail@example.com")
success = CkEmail::ckAddTo(email,"person1","person1@example.com")
success = CkEmail::ckAddTo(email,"person2","person2@example.com")
success = CkEmail::ckAddTo(email,"person3","person3@example.com")
; The SMTP server smtp.example.com won't know anything about an email address @somewhere_else.com
success = CkEmail::ckAddTo(email,"person3","person4@somewhere_else.com")
; ...
; Verify recipients.
; **** See the warning about using this API method in the description above.
; (An SMTP server only knows valid email address for its own domain. For example,
; smtp.example.com *may* only know if person1@example.com is valid or invalid, but does
; not know anything about the validity of email addresses having other domains.)
badAddrs.i = CkStringArray::ckCreate()
If badAddrs.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkMailMan::ckVerifyRecips(mailman,email,badAddrs)
If success <> 1
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
CkEmail::ckDispose(email)
CkStringArray::ckDispose(badAddrs)
ProcedureReturn
EndIf
i.i = 0
While i < CkStringArray::ckCount(badAddrs)
Debug CkStringArray::ckGetString(badAddrs,i)
i = i + 1
Wend
Debug "done."
CkMailMan::ckDispose(mailman)
CkEmail::ckDispose(email)
CkStringArray::ckDispose(badAddrs)
ProcedureReturn
EndProcedure