Saltar para o conteúdo principal
Versão: 20 R5 BETA

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

Objetos de e-mail fornecem as seguintes propriedades:

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&nbsp;&nbsp;&nbsp;&nbsp;EmailBodyValue object, containing an object for each \<partID> of bodyStructure (optional)
.cc : Text
.cc : Object
.cc : Collection
&nbsp;&nbsp;&nbsp;&nbsp;Carbon Copy (CC) additional email recipient addresse(s) of the email
.comments : Text&nbsp;&nbsp;&nbsp;&nbsp;additional comments header
.from : Text
.from : Object
.from : Collection
&nbsp;&nbsp;&nbsp;&nbsp;Originating address(es) of the email
.headers : Collection&nbsp;&nbsp;&nbsp;&nbsp;collection of EmailHeader objects, in the order they appear in the message
.htmlBody : Text&nbsp;&nbsp;&nbsp;&nbsp;HTML representation of the email message (default charset is UTF-8) (optional, SMTP only)
.id : Text&nbsp;&nbsp;&nbsp;&nbsp;unique ID from the IMAP server
.inReplyTo : Text&nbsp;&nbsp;&nbsp;&nbsp;message identifier(s) of the original message(s) to which the current message is a reply
.keywords : Object&nbsp;&nbsp;&nbsp;&nbsp;set of keywords as an object, where each property name is a keyword and each value is true
.messageId : Text&nbsp;&nbsp;&nbsp;&nbsp;message identifier header ("message-id")
.receivedAt : Text&nbsp;&nbsp;&nbsp;&nbsp;timestamp of the email's arrival on the IMAP server in ISO 8601 UTC format (ex: 2020-09-13T16:11:53Z)
.references : Collection&nbsp;&nbsp;&nbsp;&nbsp;Collection of all message-ids of messages in the preceding reply chain
.replyTo : Text
.replyTo : Object
.replyTo : Collection
&nbsp;&nbsp;&nbsp;&nbsp;addresse(s) for responses
.sendAt : Text&nbsp;&nbsp;&nbsp;&nbsp;Email timestamp in ISO 8601 UTC format
.sender : Text
.sender : Object
.sender : Collection
&nbsp;&nbsp;&nbsp;&nbsp;email source addresse(s) of the email
.size : Integer&nbsp;&nbsp;&nbsp;&nbsp;size (expressed in bytes) of the Email object returned by the IMAP server
.subject : Text&nbsp;&nbsp;&nbsp;&nbsp;description of topic
.textBody : Text&nbsp;&nbsp;&nbsp;&nbsp;Plain text representation of the email message (default charset is UTF-8) (optional, SMTP only)
.to : Text
.to : Object
.to : Collection
&nbsp;&nbsp;&nbsp;&nbsp;primary recipient addresse(s) of the email

Endereços de Email

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

Text

Object

Um objeto com duas propriedades:

PropriedadeTipoDescrição
nameTextNome de exibição (pode ser nulo)
emailTextEndereço de Email

Collection

Uma coleção de objetos de endereço.

Gesttão do corpo do correio eletrônico

The textBody and htmlBody properties are only used with the SMTP.send() function to allow sending simple mails. Quando ambas as propriedades são preenchidas, o tipo de conteúdo MIME multiparte/alternativo é utilizada. O cliente de email deve reconhecer a parte multiparte/alternativa e exibir a parte do texto ou html conforme necessário.

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.

Exemplo de objetos bodyStructure e 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

Descrição

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

Descrição

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

.bodyStructure

.bodyStructure : Object

Descrição

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:

PropriedadeTipoValor
partIDTextIdentifica a parte de maneira única dentro do email
typeText(obrigatório) Valor do campo de cabeçalho Content-Type da parte
charsetTextValor do parâmetro charset do campo de cabeçalho Content-Type
encodingTextIf isEncodingProblem=true, the Content-Transfer-Encoding value is added (by default undefined)
dispositionTextValor do campo de cabeçalho Conteúdo - Disposição da parte
LínguagemColeção 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.
subPartsUma coleção de objetosBody parts of each child (collection of EmailBodyPart objects)
headersUma coleção 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

Descrição

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:

PropriedadeTipoValor
partID.valuetextValor da parte do corpo
partID.isEncodingProblembooleanVerdadeiro se seções malformadas forem encontradas durante a decodificação do conjunto de charset, ou charset desconhecido, ou codificação de conteúdo desconhecido. Padrão é falso

.cc

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

Descrição

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

.comments

.comments : Text

Descrição

The .comments property contains an additional comments header.

Os comentários só aparecem na seção de cabeçalho da mensagem (mantendo o corpo da mensagem intocado).

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

.from

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

Descrição

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

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

  • o domínio do remetente é o que o servidor de e-mail de recebimento recebe ao abrir a sessão,
  • o endereço a partir é o que o(s) destinatário(s) verá(s).

Para uma melhor capacidade de entrega, é recomendado usar o mesmo endereço de e para o remetente.

.headers

.headers : Collection

Descrição

The .headers property contains a collection of EmailHeader objects, in the order they appear in the message. Esta propriedade permite que usuários adicionem cabeçalhos estendidos (registrados) ou definidos pelo usuário (não registrados, começando com cabeçalhos "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 da coleção de cabeçalhos pode conter as propriedades abaixo:

PropriedadeTipoValor
[].nametext(mandatory) Header field name as defined in RFC#5322. Caso seja nulo ou indefinido, o campo cabeçalho não será adicionado ao cabeçalho MIME.
[].valuetextHeader field values as defined in RFC#5322

.htmlBody

.htmlBody : Text

Descrição

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

Descrição

IMAP transporter only.

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

.inReplyTo

.inReplyTo : Text

Descrição

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

Descrição

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).

PropriedadeTipoValor
.\<keyword>booleanPalavra-chave a definir (valor deve ser verdadeiro)

Palavra-chave reservada.

  • $draft - Indica que uma mensagem é um rascunho
  • $seen - Indica uma mensagem que foi lida
  • $flagged - Indica uma mensagem que requer atenção especial (por exemplo, Urgent)
  • $answered - Indica uma mensagem que foi respondida
  • $deleted - Indica uma mensagem para deletar

Exemplo

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

.messageId

.messageId : Text

Descrição

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

Este cabeçalho geralmente é "lettersOrNumbers@domainname", por exemplo, "abcdef.123456@4d.com". Este ID exclusivo é usado em particular em fóruns ou listas públicas de e-mail. Em geral, os servidores de email adicionam automaticamente este cabeçalho às mensagens que enviam.

.receivedAt

.receivedAt : Text

Descrição

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

Descrição

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

Descrição

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

.sendAt

.sendAt : Text

Descrição

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

.sender

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

Descrição

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

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

  • o domínio do remetente é o que o servidor de e-mail de recebimento recebe ao abrir a sessão,
  • o endereço a partir é o que o(s) destinatário(s) verá(s).

Para uma melhor capacidade de entrega, é recomendado usar o mesmo endereço de e para o remetente.

.size

.size : Integer

Descrição

IMAP transporter only.

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

.subject

.subject : Text

Descrição

The .subject property contains the description of topic.

.textBody

.textBody : Text

Descrição

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

Descrição

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

MAIL Convert from MIME

História
ReleaseMudanças
18Adicionado

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

ParâmetroTipoDescrição
mimeBlob, Text->E-mail no MIME
ResultadosObject<-Objeto Email

Descrição

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. Pode ser fornecido por qualquer servidor de correio ou aplicativo. You can pass a BLOB or a text mime parameter. Se o MIME vier de um arquivo, é recomendado utilizar um parâmetro BLOB para evitar problemas relacionados ao conjunto de caracteres e conversões de quebra de linha.

Objeto devolvido

Objeto Email.

Exemplo 1

Se quiser carregar um modelo de e-mail salvo como MIME em um documento de texto e enviar um e-mail:

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)

Exemplo 2

Neste exemplo, você envia diretamente um documento 4D Write Pro contendo fotos:

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

// Mime export of the 4D Write Pro document WP EXPORT VARIABLE(WParea;$mime;wk mime html)

// convert 4D Write Pro Mime variable in mail object
$email:=MAIL Convert from MIME($mime)

// Fill your mail object headers
$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

História
ReleaseMudanças
17 R4Adicionado
17 R5Modificado

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

ParâmetroTipoDescrição
mailObject->Objeto Email
optionsObject->Opções de codificação e Charset
ResultadosText<-Email objeto convertido em MIME

Descrição

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. Ele pode ser usado para analisar o formato MIME do objeto.

In mail, pass the content and the structure details of the email to convert. Isso inclui informações como os endereços de e-mail (remetente e destinatário(s)), a própria mensagem e o tipo de exibição para a mensagem.

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

In options, you can set a specific charset and encoding configuration for the mail. As seguintes propriedades estão disponíveis:

PropriedadeTipoDescrição
headerCharsetTextCharset e codificação usados para as seguintes partes do e-mail: assunto, nomes de arquivos de anexo e atributos de nome de e-mail. 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 e codificação usados para o conteúdo html e corpo do e-mail. Valores possíveis: o mesmo que para headerCharset (ver acima)

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

Exemplo

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--