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
(PowerBuilder) 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.
integer li_rc oleobject loo_Mailman integer li_Success oleobject loo_Email oleobject loo_BdMime oleobject loo_DistList oleobject loo_SbRecipients integer i integer li_SzDistList integer j // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Mailman = create oleobject // Use "Chilkat_9_5_0.MailMan" for versions of Chilkat < 10.0.0 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 loo_Mailman.SmtpHost = "smtp.mymailserver.com" loo_Mailman.SmtpPort = 465 loo_Mailman.SmtpSsl = 1 loo_Mailman.SmtpUsername = "myUsername" loo_Mailman.SmtpPassword = "myPassword" // Create a new email object loo_Email = create oleobject // Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0 li_rc = loo_Email.ConnectToNewObject("Chilkat.Email") loo_Email.Subject = "This is a test" loo_Email.Body = "This is a test" loo_Email.From = "Senders Name <sender@example.com>" loo_Email.AddTo("Subscribers","subscribers@example.com") loo_BdMime = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_BdMime.ConnectToNewObject("Chilkat.BinData") loo_Mailman.RenderToMimeBd(loo_Email,loo_BdMime) // Load a file containing one email address per line. loo_DistList = create oleobject // Use "Chilkat_9_5_0.StringTable" for versions of Chilkat < 10.0.0 li_rc = loo_DistList.ConnectToNewObject("Chilkat.StringTable") li_Success = loo_DistList.AppendFromFile(1000,"utf-8","qa_data/distList.txt") if li_Success = 0 then Write-Debug loo_DistList.LastErrorText destroy loo_Mailman destroy loo_Email destroy loo_BdMime destroy loo_DistList return end if loo_SbRecipients = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbRecipients.ConnectToNewObject("Chilkat.StringBuilder") i = 0 li_SzDistList = loo_DistList.Count j = 0 do while i < li_SzDistList // Build a list of comma-separated recipients. if j > 0 then loo_SbRecipients.Append(",") end if loo_SbRecipients.Append(loo_DistList.StringAt(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 = li_SzDistList) then li_Success = loo_Mailman.SendMimeBd("sender@example.com",loo_SbRecipients.GetAsString(),loo_BdMime) if li_Success <> 1 then Write-Debug loo_Mailman.LastErrorText destroy loo_Mailman destroy loo_Email destroy loo_BdMime destroy loo_DistList destroy loo_SbRecipients return end if j = 0 loo_SbRecipients.Clear() end if loop li_Success = loo_Mailman.CloseSmtpConnection() if li_Success <> 1 then Write-Debug "Connection to SMTP server not closed cleanly." end if Write-Debug "Email sent to distirbution list." destroy loo_Mailman destroy loo_Email destroy loo_BdMime destroy loo_DistList destroy loo_SbRecipients |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.