Saltar al contenido principal
Versión: Siguiente

Email

Creating, sending or receiving emails in 4D is done by handling an Email object.

Email objects are created when receiving mails through a transporter class function:

You can also create a new, blank Email object and then fill it with Email object properties.

You send Email objects using the SMTP .send() function.

MAIL Convert from MIME and MAIL Convert to MIME commands can be used to convert Email objects to and from MIME contents.

Objeto Email

Los objetos Email ofrecen las siguientes propiedades:

4D follows the JMAP specification to format the Email object.

.attachments : Collection
collection of 4D.MailAttachment object(s)
.bcc : Text
.bcc : Object
.bcc : Collection

Blind Carbon Copy (BCC) hidden email recipient addresse(s) of the email
.bodyStructure : Object
EmailBodyPart object, i.e. the full MIME structure of the message body (optional)
.bodyValues : Object
EmailBodyValue object, containing an object for each \<partID> of bodyStructure (optional)
.cc : Text
.cc : Object
.cc : Collection

Carbon Copy (CC) additional email recipient addresse(s) of the email
.comments : Text
additional comments header
.from : Text
.from : Object
.from : Collection

Originating address(es) of the email
.headers : Collection
collection of EmailHeader objects, in the order they appear in the message
.htmlBody : Text
HTML representation of the email message (default charset is UTF-8) (optional, SMTP only)
.id : Text
unique ID from the IMAP server
.inReplyTo : Text
message identifier(s) of the original message(s) to which the current message is a reply
.keywords : Object
set of keywords as an object, where each property name is a keyword and each value is true
.messageId : Text
message identifier header ("message-id")
.receivedAt : Text
timestamp of the email's arrival on the IMAP server in ISO 8601 UTC format (ex: 2020-09-13T16:11:53Z)
.references : Collection
Collection of all message-ids of messages in the preceding reply chain
.replyTo : Text
.replyTo : Object
.replyTo : Collection

addresse(s) for responses
.sendAt : Text
Email timestamp in ISO 8601 UTC format
.sender : Text
.sender : Object
.sender : Collection

email source addresse(s) of the email
.size : Integer
size (expressed in bytes) of the Email object returned by the IMAP server
.subject : Text
description of topic
.textBody : Text
Plain text representation of the email message (default charset is UTF-8) (optional, SMTP only)
.to : Text
.to : Object
.to : Collection

primary recipient addresse(s) of the email

Direcciones de correo electrónico

All properties that contain email addresses (from, cc, bcc, to, sender, replyTo) accept a value of text, object, or collection type.

Text

Object

Un objeto con dos propiedades:

PropiedadTipoDescripción
nameTextNombre a mostrar (puede ser null)
emailTextCorreo electrónico

Collection

Una colección de objetos dirección.

Gestión del cuerpo del correo electrónico

The textBody and htmlBody properties are only used with the SMTP.send() function to allow sending simple mails. Cuando se llenan ambas propiedades, se utiliza el tipo MIME content-type multipart/alternative. El cliente de correo electrónico debería entonces reconocer la parte multipart/alternative y mostrar la parte texto o html según sea necesario.

bodyStructure and bodyValues are used for SMTP when the Email object is built from a MIME document, e.g. when generated by the MAIL Convert from MIME command. In this case, both bodyStructure and bodyValues properties must be passed together, and it is not recommended to use textBody and htmlBody.

Ejemplo de objetos bodyStructure y bodyValues

"bodyStructure": {
"type": "multipart/mixed",
"subParts": [
{
"partId": "p0001",
"type": "text/plain"
},
{
"partId": "p0002",
"type": "text/html"
}
]
},
"bodyValues": {
"p0001": {
"value": "I have the most brilliant plan. Let me tell you all about it."
},
"p0002": {
"value": "<!DOCTYPE html><html><head><title></title><style type=\"text/css\">div{font-size:16px}</style></head><body><div>I have the most brilliant plan. Let me tell you all about it.</div></body></html>"
}
}

.attachments

.attachments : Collection

Descripción

The .attachments property contains a collection of 4D.MailAttachment object(s).

Attachment objects are defined through the MAIL New attachment command. Attachment objects have specific properties and functions.

.bcc

.bcc : Text
.bcc : Object
.bcc : Collection

Descripción

The .bcc property contains the Blind Carbon Copy (BCC) hidden email recipient addresse(s) of the email.

.bodyStructure

.bodyStructure : Object

Descripción

The .bodyStructure property contains the EmailBodyPart object, i.e. the full MIME structure of the message body (optional). See Handling body part section.

The .bodyStructure object contains the following properties:

PropiedadTipoValor
partIDTextIdentifica la parte de manera única dentro del correo electrónico
typeText(obligatorio) Valor del campo del encabezado Content-Type de la parte
charsetTextValor del parámetro charset del campo del encabezado Content-Type
encodingTextIf isEncodingProblem=true, the Content-Transfer-Encoding value is added (by default undefined)
dispositionTextValor del campo del encabezado Content-Disposition de la parte
lenguajeColección de textosList of language tags, as defined in RFC3282, in the Content-Language header field of the part, if present.
locationTextURI, as defined in RFC2557, in the Content-Location header field of the part, if present.
subPartsColección de objetosBody parts of each child (collection of EmailBodyPart objects)
headersColección de objetosList of all header fields in the part, in the order they appear in the message (collection of EmailHeader objects, see headers property)

.bodyValues

.bodyValues : Object

Descripción

The .bodyValues property contains the EmailBodyValue object, containing an object for each \<partID> of bodyStructure (optional). See Handling body part section.

The .bodyValues object contains the following properties:

PropiedadTipoValor
partID.valuetextValor de la parte del cuerpo
partID.isEncodingProblembooleanTrue si se encuentran secciones malformadas al decodificar el conjunto de caracteres, o el conjunto de caracteres desconocido, o la codificación de transferencia de contenido desconocida. Falso por defecto

.cc

.cc : Text
.cc : Object
.cc : Collection

Descripción

The .cc property contains the Carbon Copy (CC) additional email recipient addresse(s) of the email.

.comments

.comments : Text

Descripción

The .comments property contains an additional comments header.

Los comentarios sólo aparecen en la sección del encabezado del mensaje (manteniendo el cuerpo del mensaje intacto).

For specific formatting requirements, please consult the RFC#5322.

.from

.from : Text
.from : Object
.from : Collection

Descripción

The .from property contains the Originating address(es) of the email.

Each email you send out has both the sender and from addresses:

  • el dominio sender es el que obtiene el servidor de recepción del email al abrir la sesión,
  • la dirección from es lo que verán los destinatarios.

Para mejorar la entregabilidad, se recomienda utilizar las mismas direcciones para from y sender.

.headers

.headers : Collection

Descripción

The .headers property contains a collection of EmailHeader objects, in the order they appear in the message. Esta propiedad permite a los usuarios añadir encabezados extendidos (registrados) o definidos por el usuario (no registrados, que comienzan por "X").

If an EmailHeader object property defines a header such as "from" or "cc" which is already set as a property at the mail level, the EmailHeader property is ignored.

Cada objeto de la colección de encabezados puede contener las siguientes propiedades:

PropiedadTipoValor
[].nametext(mandatory) Header field name as defined in RFC#5322. Si es null o indefinido, el campo encabezado no se agrega al encabezado MIME.
[].valuetextHeader field values as defined in RFC#5322

.htmlBody

.htmlBody : Text

Descripción

The .htmlBody property contains the HTML representation of the email message (default charset is UTF-8) (optional, SMTP only). See Handling body part section.

.id

.id : Text

Descripción

IMAP transporter only.

The .id property contains the unique ID from the IMAP server.

.inReplyTo

.inReplyTo : Text

Descripción

The .inReplyTo property contains the message identifier(s) of the original message(s) to which the current message is a reply.

For specific formatting requirements, please consult the RFC#5322.

.keywords

.keywords : Object

Descripción

The .keywords property contains a set of keywords as an object, where each property name is a keyword and each value is true.

This property is the "keywords" header (see RFC#4021).

PropiedadTipoValor
.\<keyword>booleanPalabra clave a definir (el valor debe ser true)

Palabras clave reservadas:

  • $draft - Indica que un mensaje es un borrador
  • $seen - Indica que se ha leído un mensaje
  • $flagged - Indica que un mensaje necesita atención especial (por ejemplo, urgente)
  • $answered - Indica que se ha respondido un mensaje
  • $deleted - Indica un mensaje a eliminar

Ejemplo

 $mail.keywords["$flagged"]:=True
$mail.keywords["4d"]:=True

.messageId

.messageId : Text

Descripción

The .messageId property contains a message identifier header ("message-id").

Este encabezado suele ser "lettersOrNumbers@domainname", por ejemplo, "abcdef.123456@4d.com". Este identificador único se utiliza, en particular, en foros o listas de correo públicas. En general, los servidores de correo añaden automáticamente este encabezado a los mensajes que envían.

.receivedAt

.receivedAt : Text

Descripción

IMAP transporter only.

The .receivedAt property contains the timestamp of the email's arrival on the IMAP server in ISO 8601 UTC format (ex: 2020-09-13T16:11:53Z).

.references

.references : Collection

Descripción

The .references property contains the Collection of all message-ids of messages in the preceding reply chain.

For specific formatting requirements, please consult the RFC#5322.

.replyTo

.replyTo : Text
.replyTo : Object
.replyTo : Collection

Descripción

The .replyTo property contains the addresse(s) for responses.

.sendAt

.sendAt : Text

Descripción

The .sendAt property contains the Email timestamp in ISO 8601 UTC format.

.sender

.sender : Text
.sender : Object
.sender : Collection

Descripción

The .sender property contains the email source addresse(s) of the email.

Each email you send out has both the sender and from addresses:

  • el dominio sender es el que obtiene el servidor de recepción del email al abrir la sesión,
  • la dirección from es lo que verán los destinatarios.

Para mejorar la entregabilidad, se recomienda utilizar las mismas direcciones para from y sender.

.size

.size : Integer

Descripción

IMAP transporter only.

The .size property contains the size (expressed in bytes) of the Email object returned by the IMAP server.

.subject

.subject : Text

Descripción

The .subject property contains the description of topic.

.textBody

.textBody : Text

Descripción

The .textBody property contains the Plain text representation of the email message (default charset is UTF-8) (optional, SMTP only). See Handling body part section.

.to

.to : Text
.to : Object
.to : Collection

Descripción

The .to property contains the primary recipient addresse(s) of the email.

MAIL Convert from MIME

Historia
LanzamientoModificaciones
18Añadidos

MAIL Convert from MIME( mime : Blob ) : Object
MAIL Convert from MIME( mime : Text ) : Object

ParámetrosTipoDescripción
mimeBlob, Text->Email en MIME
ResultObject<-Objeto Email

Descripción

The MAIL Convert from MIME command converts a MIME document into a valid email object.

4D follows the JMAP specification to format the returned email object.

Pass in mime a valid MIME document to convert. Puede ser suministrado por cualquier servidor o aplicación de correo. You can pass a BLOB or a text mime parameter. Si el MIME proviene de un archivo, se recomienda utilizar un parámetro BLOB para evitar problemas relacionados con las conversiones del conjunto de caracteres y los saltos de línea.

Objeto devuelto

Objeto Email.

Ejemplo 1

Quiere cargar una plantilla de correo guardada como MIME en un documento de texto y enviar un correo electrónico:

var $mime: Blob
var $mail;$server;$transporter;$status: Object

$mime:=File("/PACKAGE/Mails/templateMail.txt").getContent())

$mail:=MAIL Convert from MIME($mime)
$mail.to:="smith@mail.com"
$mail.subject:="Hello world"

$server:=New object
$server.host:="smtp.gmail.com"
$server.port:=465
$server.user:="test@gmail.com"
$server.password:="XXXX"

$transporter:=SMTP New transporter($server)
$status:=$transporter.send($mail)

Ejemplo 2

En este ejemplo, se envía directamente un documento de 4D Write Pro que contiene imágenes:

var $mime: Blob
var $email;$server;$transporter;$status: Object

// Exportación Mime del documento 4D Write Pro
WP EXPORT VARIABLE(WParea;$mime;wk mime html)

// convertir la variable Mime de 4D Write Pro en objeto email
$email:=MAIL Convert from MIME($mime)

// Llenar los encabezados del objeto email
$email.subject:="4D Write Pro HTML body"
$email.from:="YourEmail@gmail.com"
$email.to:="RecipientEmail@mail.com"

$server:=New object
$server.host:="smtp.gmail.com"
$server.port:=465
$server.user:="YourEmail@gmail.com"
$server.password:="XXXX"

$transporter:=SMTP New transporter($server)
$status:=$transporter.send($email)

MAIL Convert to MIME

Historia
LanzamientoModificaciones
17 R4Añadidos
17 R5Modificado

MAIL Convert to MIME( mail : Object { ; options : Object } ) : Text

ParámetrosTipoDescripción
mailObject->Objeto Email
optionsObject->Opciones de codificación y de charset del mail
ResultText<-Objeto email convertido en MIME

Descripción

The MAIL Convert to MIME command converts an email object into MIME text. This command is called internally by SMTP_transporter.send( ) to format the email object before sending it. Se puede utilizar para analizar el formato MIME del objeto.

In mail, pass the content and the structure details of the email to convert. Esto incluye información como las direcciones de correo electrónico (remitente y destinatario(s)), el propio mensaje y el tipo de visualización del mensaje.

4D follows the JMAP specification to format the email object.

In options, you can set a specific charset and encoding configuration for the mail. Las siguientes propiedades están disponibles:

PropiedadTipoDescripción
headerCharsetTextCharset y codificación utilizados para las siguientes partes del correo electrónico: asunto, nombres de archivos adjuntos y atributo(s) del nombre del correo electrónico. Possible values:
ConstantValueComment
mail mode ISO2022JPUS-ASCII_ISO-2022-JP_UTF8_QP
  • headerCharset: US-ASCII if possible, Japanese (ISO-2022-JP) & Quoted-printable if possible, otherwise UTF-8 & Quoted-printable
  • bodyCharset: US-ASCII if possible, Japanese (ISO-2022-JP) & 7-bit if possible, otherwise UTF-8 & Quoted-printable
mail mode ISO88591ISO-8859-1
  • headerCharset: ISO-8859-1 & Quoted-printable
  • bodyCharset: ISO-8859-1 & 8-bit
mail mode UTF8US-ASCII_UTF8_QPheaderCharset & bodyCharset: US-ASCII if possible, otherwise UTF-8 & Quoted-printable (default value)
mail mode UTF8 in base64US-ASCII_UTF8_B64headerCharset & bodyCharset: US-ASCII if possible, otherwise UTF-8 & base64
bodyCharsetTextCharset y codificación utilizados para el contenido html y el texto del cuerpo del correo electrónico. Valores posibles: los mismos que para headerCharset (ver arriba)

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

Ejemplo

var $mail: Object
var $mime: Text
$mail:=New object

// Creation of a mail
$mail.from:="tsales@massmarket.com"
$mail.subject:="Terrific Sale! This week only!"
$mail.textBody:="Text format email"
$mail.htmlBody:="<html><body>HTML format email</body></html>"
$mail.to:=New collection
$mail.to.push(New object ("email";"noreply@4d.com"))
$mail.to.push(New object ("email";"test@4d.com"))

// transform the mail object in MIME
$mime:=MAIL Convert to MIME($mail)

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