Name
msg:build — Create a message
Synopsis
msg:build(headers, parts, attachments);
headers: table parts: table attachments: array of userdata
Description
When calling this function, msg must be an empty message (created using msys.core.ec_message_new()). It requires the following inputs:
-
headersa table ofheader name/header valuepairs. If the header's value contains non-ASCII or non-printable ASCII text, the caller must encode the text appropriately (see RFC 2047). -
partsa table of alternative contents. Each pair consists ofcontent-type/contentpairs. For example, "text/plain; charset=utf8" / "Momentum 3.1 rocks."; "text/html" / "Momentum 3.1 rocks.". "If the value of Content-Type is
text/*and there is no charset specified, the content will be quoted-printable encoded; if a charset is specified or content type is nottext/*, the content will be base64 encoded. -
attachmentsan array of attachment objects. Each element is a table representing an attachment. The attachment table must contain the following pairs:-
typethe "content-type" of the attachment. If your content charset encoding is not UTF-8, you will need to specify it in here as a parameter. For example: charset=charset_encoding. -
namea file name.Note
If the file is in the current directory, you cannot use the file name alone. As a workaround, precede the file name with
./, for example,./attachment.txt. -
headersa string of concatenated headers. Such as "Openby: iphone4\r\nCertificate: AKJSdwuiqdQIWDUHQIWDUH". Note that there should not be a CRLF at end. -
contentthe content of the attachment. The value can be a string, an io_object or an ec_message. For a string, the content will be quoted-printable encoded for transferring; for an io_object, the content will be base64 encoded. It is the caller's responsibility to encode the io_object. When the content is an ec_message, values of type, name or headers are ignored. The ec_message will be treated as an attached mail with content-type equal tomessage/rfc822; name="Attached Message".
-
Enable this function with the statement require('msys.extended.message');.
When it is complete the message will have the following structure:
Content-Type: multipart/mixed; boundary="_bbb_" Other-headers --_bbb_ Content-Type: multipart/alternative; boundary="_ccc_" Other-headers --_ccc_ Content-Type: text/plain Content-Disposition: inline Other-headers <the content of plain mail> --_ccc_ Content-Type: text/html Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Other-headers <the content of html mail> --_ccc_ ... ... other parts ... --_ccc_-- --_bbb_ Content-type: attachment; name=cool-app.exe other headers Content-Transfer-Encoding: base64 <base64 encoded binary> --_bbb_ ... ... other attachments ... --_bbb_-- .