Sample code for 30+ languages & platforms
Lianja

Create Email with Non-Standard Binary Body

Creates an email where the only body is a binary WAV file. The technique used in the example could be applied to other binary files, such as PDF, MS-WORD docs, Excel docs, etc.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

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

loMime = createobject("CkMime")

llSuccess = loMime.SetBodyFromFile("VoiceMessage.wav")
if (llSuccess = .F.) then
    ? loMime.LastErrorText
    release loMime
    return
endif

// The MIME has this header:
// Content-Disposition: attachment;
// 	 filename="VoiceMessage.wav"
// Content-Transfer-Encoding: base64
// Content-Type: audio/x-wav;
// 	name="VoiceMessage.wav"

// We don't want the content-disposition to be an
// attachment -- otherwise the email object will self-correct
// and put it in a multipart/mixed format...
loMime.Disposition = ""
loMime.Filename = ""

lcStrMime = loMime.GetMime()
? lcStrMime

// Now load it into an email object:
loEmail = createobject("CkEmail")
llSuccess = loEmail.SetFromMimeText(lcStrMime)
if (llSuccess = .F.) then
    ? loEmail.LastErrorText
    release loMime
    release loEmail
    return
endif

// Add subject, TO, FROM, etc.
loEmail.Subject = "This is a test"
loEmail.From = "support@chilkatsoft.com"
llSuccess = loEmail.AddTo("Matt","matt@chilkatsoft.com")

// Your email is ready to send.
// (but for this example, we'll simply save it to a file...)
llSuccess = loEmail.SaveEml("email.eml")
if (llSuccess = .F.) then
    ? loEmail.LastErrorText
    release loMime
    release loEmail
    return
endif

? "OK!"


release loMime
release loEmail