PureBasic Requires Chilkat v11.0.0+
PureBasic
Create an email with plain-text and HTML bodies
See more Email Object Examples
Set the From and Reply-To addresses, add a recipient, and provide plain-text and HTML versions of the same body. Save the message as text-and-html.eml.
Chilkat PureBasic Downloads
IncludeFile "CkEmail.pb"
Procedure ChilkatExample()
success.i = 0
; Assumes Chilkat is unlocked. See Global Unlock Sample.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkFromName(email, "Sam Lee")
CkEmail::setCkFromAddress(email, "sam@example.com")
CkEmail::setCkReplyTo(email, "replies@example.com")
success = CkEmail::ckAddTo(email,"Alex Rivera","alex@example.net")
If success <> 1
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
CkEmail::setCkSubject(email, "Sample message")
CkEmail::setCkCharset(email, "utf-8")
; A custom header can carry a reference alongside the standard message fields.
CkEmail::ckAddHeaderField(email,"X-Reference-ID","REF-42")
success = CkEmail::ckAddPlainTextAlternativeBody(email,"Read more at https://example.com/details.")
If success <> 1
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
success = CkEmail::ckAddHtmlAlternativeBody(email,"<p><a href='https://example.com/details'>Read more</a></p>")
If success <> 1
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
success = CkEmail::ckSaveEml(email,"text-and-html.eml")
If success <> 1
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
Debug "Saved text-and-html.eml."
CkEmail::ckDispose(email)
ProcedureReturn
EndProcedure