Sample code for 30+ languages & platforms
DataFlex

Send Email with a vCard

Demonstrates how to create a simple email, attach a vcard, and send it.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMailman
    Variant vEmail
    Handle hoEmail
    String sVcard
    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.
    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 vcard test"
    Set ComBody Of hoEmail To "This is a vcard test"
    Set ComFrom Of hoEmail To "Chilkat Admin <admin@chilkatsoft.com>"
    Get ComAddTo Of hoEmail "Chilkat Support" "support@chilkatsoft.com" To iSuccess
    // To add more recipients, call AddTo, AddCC, or AddBcc once per recipient.

    // A vCard is an email attachment having a Content-Type = "text/x-vcard".
    // Call AddStringAttachment to add a vcard from an in-memory string.
    // The filename should have a ".vcf" file extension.  Chilkat will automatically
    // recognize it and set the content-type to "text/x-vcard";

    // Your application is responsible for providing the vcard formatted string.  For example:
    // See http://en.wikipedia.org/wiki/VCard
    // 
    // begin:vcard
    // fn:Matt Smith
    // n:Smith;Matt
    // org:Chilkat Software, Inc.
    // tel;work:630-784-9670
    // url:http://www.chilkatsoft.com
    // version:2.1
    // end:vcard

    Move "begin:vcard ..." To sVcard
    Get ComAddStringAttachment Of hoEmail "admin.vcf" sVcard To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

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

    // Some SMTP servers do not actually send the email until 
    // the connection is closed.  In these cases, it is necessary to
    // call CloseSmtpConnection for the mail to be  sent.  
    // Most SMTP servers send the email immediately, and it is 
    // not required to close the connection.  We'll close it here
    // for the example:
    Get ComCloseSmtpConnection Of hoMailman To iSuccess
    If (iSuccess <> True) Begin
        Showln "Connection to SMTP server not closed cleanly."
    End

    Showln "Mail with vCard Sent!"


End_Procedure