Sample code for 30+ languages & platforms
Xbase++

Add File Attachments to an Email

Demonstrates how to add one or more file attachments to an email.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oEmail
LOCAL cContentType

nSuccess := 0

oEmail := CreateObject("Chilkat.Email")

oEmail:Subject := "This is a test"
oEmail:Body := "This is a test"
oEmail:From := "support@chilkatsoft.com"
nSuccess := oEmail:AddTo("Chilkat Admin", "admin@chilkatsoft.com")

//  To add file attachments to an email, call AddFileAttachment
//  once for each file to be attached.  The method returns
//  the content-type of the attachment if successful, otherwise
//  returns cknull

cContentType := oEmail:AddFileAttachment("something.pdf")
IF (oEmail:LastMethodSuccess != 1)
    ? oEmail:LastErrorText
    oEmail:destroy()
    RETURN
ENDIF

cContentType := oEmail:AddFileAttachment("something.xml")
IF (oEmail:LastMethodSuccess != 1)
    ? oEmail:LastErrorText
    oEmail:destroy()
    RETURN
ENDIF

cContentType := oEmail:AddFileAttachment("something.zip")
IF (oEmail:LastMethodSuccess != 1)
    ? oEmail:LastErrorText
    oEmail:destroy()
    RETURN
ENDIF

nSuccess := oEmail:SaveEml("email.eml")
IF (nSuccess == 0)
    ? oEmail:LastErrorText
    oEmail:destroy()
    RETURN
ENDIF

? "Saved EML!"

oEmail:destroy()