Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMailman
    String sTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatMailMan)) To hoMailman
    If (Not(IsComObjectCreated(hoMailman))) Begin
        Send CreateComObject of hoMailman
    End

    //  SMTP authentication settings (the SMTP server hostname is passed to QuickSend).
    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"

    //  Send a simple email in one call.

    Get ComQuickSend Of hoMailman "alice@example.com" "bob@example.com" "Quick hello" "This is a quick message." "smtp.example.com" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "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.


End_Procedure