DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoMailman
Variant vBundle
Handle hoBundle
Variant vEmail1
Handle hoEmail1
Variant vEmail2
Handle hoEmail2
String sTemp1
Integer iTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatMailMan)) To hoMailman
If (Not(IsComObjectCreated(hoMailman))) Begin
Send CreateComObject of hoMailman
End
// Configure the SMTP server connection.
Set ComSmtpHost Of hoMailman To "smtp.example.com"
Set ComSmtpPort Of hoMailman To 465
Set ComSmtpSsl Of hoMailman To True
Set ComSmtpUsername Of hoMailman To "user@example.com"
Set ComSmtpPassword Of hoMailman To "myPassword"
// Build a bundle of emails to send.
Get Create (RefClass(cComChilkatEmailBundle)) To hoBundle
If (Not(IsComObjectCreated(hoBundle))) Begin
Send CreateComObject of hoBundle
End
Get Create (RefClass(cComChilkatEmail)) To hoEmail1
If (Not(IsComObjectCreated(hoEmail1))) Begin
Send CreateComObject of hoEmail1
End
Set ComSubject Of hoEmail1 To "Message 1"
Set ComFrom Of hoEmail1 To "alice@example.com"
Get ComAddTo Of hoEmail1 "Bob" "bob@example.com" To iSuccess
Set ComBody Of hoEmail1 To "This is the first message."
Get pvComObject of hoEmail1 to vEmail1
Get ComAddEmail Of hoBundle vEmail1 To iSuccess
Get Create (RefClass(cComChilkatEmail)) To hoEmail2
If (Not(IsComObjectCreated(hoEmail2))) Begin
Send CreateComObject of hoEmail2
End
Set ComSubject Of hoEmail2 To "Message 2"
Set ComFrom Of hoEmail2 To "alice@example.com"
Get ComAddTo Of hoEmail2 "Carol" "carol@example.com" To iSuccess
Set ComBody Of hoEmail2 To "This is the second message."
Get pvComObject of hoEmail2 to vEmail2
Get ComAddEmail Of hoBundle vEmail2 To iSuccess
// Send every email in the bundle.
Get pvComObject of hoBundle to vBundle
Get ComSendBundle Of hoMailman vBundle To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoMailman To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComMessageCount Of hoBundle To iTemp1
Showln "Sent " iTemp1 " 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.
End_Procedure