PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Bundle
oleobject loo_Email1
oleobject loo_Email2
li_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.
loo_Mailman = create oleobject
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
// Configure the SMTP server connection.
loo_Mailman.SmtpHost = "smtp.example.com"
loo_Mailman.SmtpPort = 465
loo_Mailman.SmtpSsl = 1
loo_Mailman.SmtpUsername = "user@example.com"
loo_Mailman.SmtpPassword = "myPassword"
// Build a bundle of emails to send.
loo_Bundle = create oleobject
li_rc = loo_Bundle.ConnectToNewObject("Chilkat.EmailBundle")
loo_Email1 = create oleobject
li_rc = loo_Email1.ConnectToNewObject("Chilkat.Email")
loo_Email1.Subject = "Message 1"
loo_Email1.From = "alice@example.com"
loo_Email1.AddTo("Bob","bob@example.com")
loo_Email1.Body = "This is the first message."
loo_Bundle.AddEmail(loo_Email1)
loo_Email2 = create oleobject
li_rc = loo_Email2.ConnectToNewObject("Chilkat.Email")
loo_Email2.Subject = "Message 2"
loo_Email2.From = "alice@example.com"
loo_Email2.AddTo("Carol","carol@example.com")
loo_Email2.Body = "This is the second message."
loo_Bundle.AddEmail(loo_Email2)
// Send every email in the bundle.
li_Success = loo_Mailman.SendBundle(loo_Bundle)
if li_Success = 0 then
Write-Debug loo_Mailman.LastErrorText
destroy loo_Mailman
destroy loo_Bundle
destroy loo_Email1
destroy loo_Email2
return
end if
Write-Debug "Sent " + string(loo_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.
destroy loo_Mailman
destroy loo_Bundle
destroy loo_Email1
destroy loo_Email2