Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Send Email to Distribution ListSends the same email to a list of 1000 email addresses in 50 sends where each email has 20 recipients. Note: Chilkat is not intended nor designed for mass emailing. A solution such as this might be used for a corporate emailing to employees, or an emailing to newsletter subscribers.
IncludeFile "CkBinData.pb" IncludeFile "CkStringTable.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkEmail.pb" IncludeFile "CkMailMan.pb" Procedure ChilkatExample() ; 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 success.i CkMailMan::setCkSmtpHost(mailman, "smtp.mymailserver.com") CkMailMan::setCkSmtpPort(mailman, 465) CkMailMan::setCkSmtpSsl(mailman, 1) CkMailMan::setCkSmtpUsername(mailman, "myUsername") CkMailMan::setCkSmtpPassword(mailman, "myPassword") ; 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, "Senders Name <sender@example.com>") CkEmail::ckAddTo(email,"Subscribers","subscribers@example.com") bdMime.i = CkBinData::ckCreate() If bdMime.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkMailMan::ckRenderToMimeBd(mailman,email,bdMime) ; Load a file containing one email address per line. distList.i = CkStringTable::ckCreate() If distList.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkStringTable::ckAppendFromFile(distList,1000,"utf-8","qa_data/distList.txt") If success = 0 Debug CkStringTable::ckLastErrorText(distList) CkMailMan::ckDispose(mailman) CkEmail::ckDispose(email) CkBinData::ckDispose(bdMime) CkStringTable::ckDispose(distList) ProcedureReturn EndIf sbRecipients.i = CkStringBuilder::ckCreate() If sbRecipients.i = 0 Debug "Failed to create object." ProcedureReturn EndIf i.i = 0 szDistList.i = CkStringTable::ckCount(distList) j.i = 0 While i < szDistList ; Build a list of comma-separated recipients. If j > 0 CkStringBuilder::ckAppend(sbRecipients,",") EndIf CkStringBuilder::ckAppend(sbRecipients,CkStringTable::ckStringAt(distList,i)) i = i + 1 j = j + 1 ; If we have 20 recipients, or we have the final recipient in the final chunk, then send. If (j = 20) OR (i = szDistList) success = CkMailMan::ckSendMimeBd(mailman,"sender@example.com",CkStringBuilder::ckGetAsString(sbRecipients),bdMime) If success <> 1 Debug CkMailMan::ckLastErrorText(mailman) CkMailMan::ckDispose(mailman) CkEmail::ckDispose(email) CkBinData::ckDispose(bdMime) CkStringTable::ckDispose(distList) CkStringBuilder::ckDispose(sbRecipients) ProcedureReturn EndIf j = 0 CkStringBuilder::ckClear(sbRecipients) EndIf Wend success = CkMailMan::ckCloseSmtpConnection(mailman) If success <> 1 Debug "Connection to SMTP server not closed cleanly." EndIf Debug "Email sent to distirbution list." CkMailMan::ckDispose(mailman) CkEmail::ckDispose(email) CkBinData::ckDispose(bdMime) CkStringTable::ckDispose(distList) CkStringBuilder::ckDispose(sbRecipients) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.