Skip to main content

mailConvertToMIME

mailConvertToMIME( mail : object { , options : object } ) : string

ParameterTypeDescription
mailobject->Email object
optionsobject->Charset and encoding mail options
Resultstring<-Email object converted to MIME

Description

The mailConvertToMIME command converts an email object into MIME string. This command is called internally by SMTP_transporter.send() to format the email object before sending it. It can be used to analyze the MIME format of the object.

In mail, pass the content and the structure details of the email to convert. This includes information such as the email addresses (sender and recipient(s)), the message itself, and the type of display for the message.

QodlyScript follows the JMAP specification to format the email object.

In options, you can set a specific charset and encoding configuration for the mail. The following properties are available:

PropertyTypeDescription
headerCharsetstringCharset and encoding used for the following parts of the email: subject, attachment filenames, and email name attribute(s). Possible values:
ConstantValueComment
kMailModeUTF8US-ASCII_UTF8_QPheaderCharset & bodyCharset: US-ASCII if possible, otherwise UTF-8 & Quoted-printable (default value)
kMailModeUTF8InBase64US-ASCII_UTF8_B64headerCharset & bodyCharset: US-ASCII if possible, otherwise UTF-8 & base64
bodyCharsetstringCharset and encoding used for the html and string body contents of the email. Possible values: Same as for headerCharset (see above)

If the options parameter is omitted, the mail mode UTF8 configuration is used for header and body parts.

Example

var mail: object
var mime: string
mail = newObject

// Creation of a mail
mail.from = "tsales@massmarket.com"
mail.subject = "Terrific Sale! This week only!"
mail.stringBody = "string format email"
mail.htmlBody = "<html><body>HTML format email</body></html>"
mail.to = newcollection
mail.to.push(newObject("email","noreply@4d.com"))
mail.to.push(newObject("email","test@4d.com"))

// transform the mail object in MIME
mime = mailConvertToMIME(mail)

// Contents of mime:
// MIME-Version: 1.0
// Date: Thu, 15 Dec 2022 15:42:25 GMT
// Message-ID: <7CA5D25B2B5E0047A36F2E8CB30362E2>
// Sender: tsales@massmarket.com
// From: tsales@massmarket.com
// To: noreply@qodly.com
// To: test@qodly.com
// Content-Type: multipart/alternative, boundary = "E0AE5773D5E95245BBBD80DD0687E218"
// Subject: Terrific Sale! This week only!
//
// --E0AE5773D5E95245BBBD80DD0687E218
// Content-Type: string/plain, charset = "UTF-8"
// Content-Transfer-Encoding: quoted-printable
//
// string format email
// --E0AE5773D5E95245BBBD80DD0687E218
// Content-Type: string/html, charset = "UTF-8"
// Content-Transfer-Encoding: quoted-printable
//
// <html><body>HTML format email</body></html>
// --E0AE5773D5E95245BBBD80DD0687E218--