Sample code for 30+ languages & platforms
AutoIt

Send Email to Distribution List

See more SMTP Examples

Sends 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.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oMailman = ObjCreate("Chilkat.MailMan")

$oMailman.SmtpHost = "smtp.mymailserver.com"
$oMailman.SmtpPort = 465
$oMailman.SmtpSsl = True
$oMailman.SmtpUsername = "myUsername"
$oMailman.SmtpPassword = "myPassword"

; Create a new email object
$oEmail = ObjCreate("Chilkat.Email")
$oEmail.Subject = "This is a test"
$oEmail.Body = "This is a test"
$oEmail.From = "Senders Name <sender@example.com>"
$oEmail.AddTo("Subscribers","subscribers@example.com")

$oBdMime = ObjCreate("Chilkat.BinData")
$oMailman.RenderToMimeBd($oEmail,$oBdMime)

; Load a file containing one email address per line.
$oDistList = ObjCreate("Chilkat.StringTable")
$bSuccess = $oDistList.AppendFromFile(1000,"utf-8","qa_data/distList.txt")
If ($bSuccess = False) Then
    ConsoleWrite($oDistList.LastErrorText & @CRLF)
    Exit
EndIf

$oSbRecipients = ObjCreate("Chilkat.StringBuilder")

Local $i = 0
Local $iSzDistList = $oDistList.Count
Local $iJ = 0
While $i < $iSzDistList

    ; Build a list of comma-separated recipients.
    If ($iJ > 0) Then
        $oSbRecipients.Append(",")
    EndIf

    $oSbRecipients.Append($oDistList.StringAt($i))

    $i = $i + 1
    $iJ = $iJ + 1

    ; If we have 20 recipients, or we have the final recipient in the final chunk, then send.
    If (($iJ = 20) Or ($i = $iSzDistList)) Then
        $bSuccess = $oMailman.SendMimeBd("sender@example.com",$oSbRecipients.GetAsString(),$oBdMime)
        If ($bSuccess <> True) Then
            ConsoleWrite($oMailman.LastErrorText & @CRLF)
            Exit
        EndIf

        $iJ = 0
        $oSbRecipients.Clear 
    EndIf

Wend

$bSuccess = $oMailman.CloseSmtpConnection()
If ($bSuccess <> True) Then
    ConsoleWrite("Connection to SMTP server not closed cleanly." & @CRLF)
EndIf

ConsoleWrite("Email sent to distirbution list." & @CRLF)