Sample code for 30+ languages & platforms
VBScript

Send a Bundle of Emails via SMTP

See more SMTP Examples

Demonstrates the Chilkat MailMan.SendBundle method, which sends each email in an EmailBundle. This is equivalent to calling SendEmail once for each email in the bundle. This example builds a bundle of two messages and sends them.

Background: Sending a bundle lets Chilkat reuse a single SMTP connection for all the messages, avoiding the connect/authenticate overhead of sending them one at a time — the same efficiency as the explicit open/send-loop/close pattern, in one call. It is handy for dispatching a queued batch of distinct messages (as opposed to one message to many recipients).

Chilkat VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

'  Demonstrates the MailMan.SendBundle method, which sends each email in an EmailBundle.
'  This is equivalent to calling SendEmail once for each email in the bundle.

set mailman = CreateObject("Chilkat.MailMan")

'  Configure the SMTP server connection.
mailman.SmtpHost = "smtp.example.com"
mailman.SmtpPort = 465
mailman.SmtpSsl = 1
mailman.SmtpUsername = "user@example.com"
mailman.SmtpPassword = "myPassword"

'  Build a bundle of emails to send.
set bundle = CreateObject("Chilkat.EmailBundle")

set email1 = CreateObject("Chilkat.Email")
email1.Subject = "Message 1"
email1.From = "alice@example.com"
success = email1.AddTo("Bob","bob@example.com")
email1.Body = "This is the first message."
success = bundle.AddEmail(email1)

set email2 = CreateObject("Chilkat.Email")
email2.Subject = "Message 2"
email2.From = "alice@example.com"
success = email2.AddTo("Carol","carol@example.com")
email2.Body = "This is the second message."
success = bundle.AddEmail(email2)

'  Send every email in the bundle.

success = mailman.SendBundle(bundle)
If (success = 0) Then
    outFile.WriteLine(mailman.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine("Sent " & bundle.MessageCount & " emails.")

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

outFile.Close