Sample code for 30+ languages & platforms
DataFlex

Send High Priority Email (SMTP, X-Priority header)

Demonstrates how to send high-priorty email (or lower priority email) by setting the X-Priority header field.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMailman
    Variant vEmail
    Handle hoEmail
    String sTemp1

    Move False To iSuccess

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // The mailman object is used for sending and receiving email.
    Get Create (RefClass(cComChilkatMailMan)) To hoMailman
    If (Not(IsComObjectCreated(hoMailman))) Begin
        Send CreateComObject of hoMailman
    End

    // Set the SMTP server (obviously, use your SMTP server, not chilkatsoft.com)
    Set ComSmtpHost Of hoMailman To "smtp.chilkatsoft.com"

    // Set the SMTP login/password (if required)
    Set ComSmtpUsername Of hoMailman To "myUsername"
    Set ComSmtpPassword Of hoMailman To "myPassword"

    // Create a new email object
    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    Set ComSubject Of hoEmail To "This is a test"
    Set ComBody Of hoEmail To "This is a test"
    Set ComFrom Of hoEmail To "Chilkat Support <support@chilkatsoft.com>"
    Get ComAddTo Of hoEmail "Chilkat Admin" "admin@chilkatsoft.com" To iSuccess
    // To add more recipients, call AddTo, AddCC, or AddBcc once per recipient.

    // To send high-priority email, 
    // add the X-Priority header field with the value "1" 
    // to indicate highest-priority.
    // A value of "3" is normal, which is the same as not setting
    // the X-Priority header at all, and "5" is the lowest. 
    // "2" and "4" are in-betweens.

    // Microsoft Outlook might add the following headers when
    // sending high-priority email.

    // X-Priority: 1 (Highest) 
    // X-MSMail-Priority: High 
    // Importance: High 

    // The X-Priority header alone is enough to make the email high-priority.

    Send ComAddHeaderField To hoEmail "X-Priority" "1"

    // Call SendEmail to connect to the SMTP server and send.
    // The connection (i.e. session) to the SMTP server remains
    // open so that subsequent SendEmail calls may use the
    // same connection.  
    Get pvComObject of hoEmail to vEmail
    Get ComSendEmail Of hoMailman vEmail To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComCloseSmtpConnection Of hoMailman To iSuccess
    If (iSuccess <> True) Begin
        Showln "Connection to SMTP server not closed cleanly."
    End

    Showln "Mail Sent!"


End_Procedure