PureBasic
PureBasic
Quickly Send a Simple Email
See more SMTP Examples
Demonstrates the Chilkat MailMan.QuickSend method, which sends a simple email to a single recipient without requiring the application to create an Email object. The arguments are the from address, the to address, the subject, the body, and the SMTP server hostname. This example sends a plain-text message in one call.
Background:
QuickSend is a convenience for the most common case: one plain-text message to one recipient. It skips the build-an-Email-object step, so it's ideal for quick notifications and alerts. When you need more — HTML bodies, attachments, multiple recipients, Cc/Bcc, or custom headers — build an Email object and use SendEmail instead. Authentication settings still come from the MailMan properties.Chilkat PureBasic Downloads
IncludeFile "CkMailMan.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the MailMan.QuickSend method, which sends a simple email to a single
; recipient without requiring the application to create an Email object. The arguments are
; the from address, the to address, the subject, the body, and the SMTP server hostname.
mailman.i = CkMailMan::ckCreate()
If mailman.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; SMTP authentication settings (the SMTP server hostname is passed to QuickSend).
CkMailMan::setCkSmtpPort(mailman, 465)
CkMailMan::setCkSmtpSsl(mailman, 1)
CkMailMan::setCkSmtpUsername(mailman, "user@example.com")
CkMailMan::setCkSmtpPassword(mailman, "myPassword")
; Send a simple email in one call.
success = CkMailMan::ckQuickSend(mailman,"alice@example.com","bob@example.com","Quick hello","This is a quick message.","smtp.example.com")
If success = 0
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
ProcedureReturn
EndIf
Debug "Email sent."
; 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::ckDispose(mailman)
ProcedureReturn
EndProcedure