Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
mailman: HCkMailMan;
bundle: HCkEmailBundle;
email1: HCkEmail;
email2: HCkEmail;
begin
success := False;
// 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.
mailman := CkMailMan_Create();
// Configure the SMTP server connection.
CkMailMan_putSmtpHost(mailman,'smtp.example.com');
CkMailMan_putSmtpPort(mailman,465);
CkMailMan_putSmtpSsl(mailman,True);
CkMailMan_putSmtpUsername(mailman,'user@example.com');
CkMailMan_putSmtpPassword(mailman,'myPassword');
// Build a bundle of emails to send.
bundle := CkEmailBundle_Create();
email1 := CkEmail_Create();
CkEmail_putSubject(email1,'Message 1');
CkEmail_putFrom(email1,'alice@example.com');
CkEmail_AddTo(email1,'Bob','bob@example.com');
CkEmail_putBody(email1,'This is the first message.');
CkEmailBundle_AddEmail(bundle,email1);
email2 := CkEmail_Create();
CkEmail_putSubject(email2,'Message 2');
CkEmail_putFrom(email2,'alice@example.com');
CkEmail_AddTo(email2,'Carol','carol@example.com');
CkEmail_putBody(email2,'This is the second message.');
CkEmailBundle_AddEmail(bundle,email2);
// Send every email in the bundle.
success := CkMailMan_SendBundle(mailman,bundle);
if (success = False) then
begin
Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
Exit;
end;
Memo1.Lines.Add('Sent ' + IntToStr(CkEmailBundle_getMessageCount(bundle)) + ' 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.
CkMailMan_Dispose(mailman);
CkEmailBundle_Dispose(bundle);
CkEmail_Dispose(email1);
CkEmail_Dispose(email2);