DataFlex
DataFlex
Add a String Attachment to an Email
See more Email Object Examples
Demonstrates the Chilkat Email object's AddStringAttachment method, which adds an attachment directly from an in-memory string — no file needs to exist on disk. The 1st argument is the filename that is written into the MIME (it is not a path to a file that is read), and the 2nd argument is the text that becomes the attachment's body. In this example we build a simple email, attach a small CSV file namedpeople.csv straight from a string, and then print the resulting MIME so you can see the attachment embedded in the message.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoEmail
Boolean iSuccess
String sCsvData
String sTemp1
// This example demonstrates the Email object's AddStringAttachment method.
// AddStringAttachment adds an attachment directly from an in-memory string.
// The 1st argument is the filename to be placed in the MIME (not a file to be read).
// The 2nd argument is the text content that becomes the attachment body.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Email with a string attachment"
Set ComBody Of hoEmail To "See the attached CSV file."
Set ComFrom Of hoEmail To "mary@example.com"
Get ComAddTo Of hoEmail "Joe" "joe@example.com" To iSuccess
// The text content of the attachment.
Move "id,name" + (character(13)) + (character(10)) + "1,Alice" + (character(13)) + (character(10)) + "2,Bob" + (character(13)) + (character(10)) To sCsvData
// Add the string as an attachment named "people.csv".
Get ComAddStringAttachment Of hoEmail "people.csv" sCsvData To iSuccess
// Show the full MIME of the email, which now includes the attachment.
Get ComGetMime Of hoEmail To sTemp1
Showln sTemp1
End_Procedure