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:
- IMAP -
.getMail()
and.getMails()
functions to get emails from an IMAP server - POP3 -
.getMail()
function to get an email from a POP3 server.
You can also create a new, blank
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.
Objet Email
Les objets Email exposent les propriétés suivantes :
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 |
Adresses Email
All properties that contain email addresses (from
, cc
, bcc
, to
, sender
, replyTo
) accept a value of text, object, or collection type.
Text
- une adresse uniquement : "somebody@domain.com"
- single display name+email: "Somebody somebody@domain.com"
- several emails: "Somebody somebody@domain.com,me@home.org"
Object
Un objet avec deux propriétés :
Propriété | Type | Description |
---|---|---|
name | Text | Nom à afficher (peut être null) |
Text | Adresse email |
Collection
Une collection d'objets adresse.
Traitement du body
The textBody
and htmlBody
properties are only used with the SMTP.send() function to allow sending simple mails. Lorsque les deux propriétés sont remplies, le type MIME content-type multipart/alternative est utilisé. Le client email doit alors reconnaître la partie multipart/alternative et afficher la partie texte ou html nécessaire.
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
.
Exemple d'objets bodyStructure et 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
Description
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
Description
The .bcc
property contains the Blind Carbon Copy (BCC) hidden email recipient addresse(s) of the email.
.bodyStructure
.bodyStructure : Object
Description
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:
Propriété | Type | Valeur |
---|---|---|
partID | Text | Identifie la partie de manière unique dans l'email |
type | Text | (obligatoire) Valeur du champ d'en-tête Content-Type de la partie |
charset | Text | Valeur du paramètre charset du champ d'en-tête Content-Type |
encoding | Text | If isEncodingProblem=true , the Content-Transfer-Encoding value is added (by default undefined) |
disposition | Text | Valeur du champ d'en-tête Content-Disposition de la partie |
language | Collection de textes | List of language tags, as defined in RFC3282, in the Content-Language header field of the part, if present. |
location | Text | URI, as defined in RFC2557, in the Content-Location header field of the part, if present. |
subParts | Collection d'objets | Body parts of each child (collection of EmailBodyPart objects) |
headers | Collection d'objets | List 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
Description
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:
Propriété | Type | Valeur |
---|---|---|
partID.value | text | Valeur de la partie body |
partID.isEncodingProblem | boolean | Vrai si des sections malformées sont identifiées durant le décodage du charset, si le charset est inconnu, ou si le content transfer-encoding est inconnu. Faux par défaut |
.cc
.cc : Text
.cc : Object
.cc : Collection
Description
The .cc
property contains the Carbon Copy (CC) additional email recipient addresse(s) of the email.
.comments
.comments : Text
Description
The .comments
property contains an additional comments header.
Les commentaires n'apparaissent que dans la zone d'en-tête du message (le body du message reste inchangé).
For specific formatting requirements, please consult the RFC#5322.
.from
.from : Text
.from : Object
.from : Collection
Description
The .from
property contains the Originating address(es) of the email.
Each email you send out has both the sender and from addresses:
- le domaine sender correspond à ce que le serveur de réception d'email obtient à l'ouverture de la session,
- l'adresse from correspond à ce que le(s) destinataire(s) visualise(nt).
Pour mieux livrer l'email, il est recommandé d'utiliser les mêmes adresses pour from et sender.
.headers
.headers : Collection
Description
The .headers
property contains a collection of EmailHeader
objects, in the order they appear in the message. Cette propriété permet aux utilisateurs d'ajouter des en-têtes extended (enregistrés) ou des en-têtes user-defined (non enregistrés, commençant par "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, theEmailHeader
property is ignored.
Chaque objet de la collection de headers peut contenir les propriétés suivantes :
Propriété | Type | Valeur |
---|---|---|
[].name | text | (mandatory) Header field name as defined in RFC#5322. S'il est null ou indéfini, le champ en-tête n'est pas ajouté à l'en-tête MIME. |
[].value | text | Header field values as defined in RFC#5322 |
.htmlBody
.htmlBody : Text
Description
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
Description
IMAP transporter only.
The .id
property contains the unique ID from the IMAP server.
.inReplyTo
.inReplyTo : Text
Description
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
Description
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).
Propriété | Type | Valeur |
---|---|---|
.\<keyword> | boolean | Mot-clé à définir à définir (la valeur doit être mise à vrai) |
Mots-clés réservés :
- $draft - Indique qu'un message est un brouillon
- $seen - Indique qu'un message a été lu
- $flagged - Indique qu'un message nécessite une attention particulière (ex : Urgent)
- $answered - Indique qu'un message a reçu une réponse
- $deleted - Indique un message à supprimer
Exemple
$mail.keywords["$flagged"]:=True
$mail.keywords["4d"]:=True
.messageId
.messageId : Text
Description
The .messageId
property contains a message identifier header ("message-id").
Cet en-tête est généralement "desChiffresOuDesLettres@nomdededomaine", par exemple "abcdef.123456@4d.com". Cet identifiant unique est notamment utilisé sur les forums ou les listes de diffusion publiques. En général, les serveurs de messagerie ajoutent automatiquement cet en-tête aux messages qu'ils envoient.
.receivedAt
.receivedAt : Text
Description
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
Description
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
Description
The .replyTo
property contains the addresse(s) for responses.
.sendAt
.sendAt : Text
Description
The .sendAt
property contains the Email timestamp in ISO 8601 UTC format.
.sender
.sender : Text
.sender : Object
.sender : Collection
Description
The .sender
property contains the email source addresse(s) of the email.
Each email you send out has both the sender and from addresses:
- le domaine sender correspond à ce que le serveur de réception d'email obtient à l'ouverture de la session,
- l'adresse from correspond à ce que le(s) destinataire(s) visualise(nt).
Pour mieux livrer l'email, il est recommandé d'utiliser les mêmes adresses pour from et sender.
.size
.size : Integer
Description
IMAP transporter only.
The .size
property contains the size (expressed in bytes) of the Email object returned by the IMAP server.
.subject
.subject : Text
Description
The .subject
property contains the description of topic.
.textBody
.textBody : Text
Description
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
Description
The .to
property contains the primary recipient addresse(s) of the email.
MAIL Convert from MIME
Historique
Release | Modifications |
---|---|
18 | Ajout |
MAIL Convert from MIME( mime : Blob ) : Object
MAIL Convert from MIME( mime : Text ) : Object
Paramètres | Type | Description | |
---|---|---|---|
mime | Blob, Text | -> | Email en MIME |
Résultat | Object | <- | Objet email |
Description
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. Il peut être fourni par tout type de serveur ou d'application de messagerie. You can pass a BLOB or a text mime parameter. Si le MIME provient d'un fichier, il est recommandé d'utiliser un paramètre BLOB pour éviter les problèmes liés aux conversions de charset et de retours à la ligne.
Objet retourné
Objet email.
Exemple 1
Vous souhaitez charger un template mail enregistré au format MIME dans un document texte et l'envoyer par email :
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)
Exemple 2
Dans cet exemple, vous envoyez directement un document 4D Write Pro contenant des images :
var $mime: Blob
var $email;$server;$transporter;$status: Object
// Export Mime du document 4D Write Pro
WP EXPORT VARIABLE(WParea;$mime;wk mime html)
// convertir la variable Mime de 4D Write Pro en objet email
$email:=MAIL Convert from MIME($mime)
// Remplir les en-têtes de l'objet 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
Historique
Release | Modifications |
---|---|
17 R4 | Ajout |
17 R5 | Modifié |
MAIL Convert to MIME( mail : Object { ; options : Object } ) : Text
Paramètres | Type | Description | |
---|---|---|---|
Object | -> | Objet email | |
options | Object | -> | Options d'encodage et de charset du mail |
Résultat | Text | <- | Objet email converti en MIME |
Description
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. Elle peut être utilisée pour analyser le format MIME de l'objet.
In mail, pass the content and the structure details of the email to convert. Cela inclut des informations telles que les adresses e-mail (expéditeur et destinataire(s)), le contenu de l'e-mail lui-même et son type d'affichage.
4D follows the JMAP specification to format the email object.
In options, you can set a specific charset and encoding configuration for the mail. Les propriétés suivantes sont disponibles :
Propriété | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
headerCharset | Text | Charset et encodage utilisés pour les parties de mail suivantes : le sujet, les noms de fichiers joints et le nom du mail. Possible values:
| |||||||||||||||
bodyCharset | Text | Charset et encodage utilisés pour le contenu html et le texte du body du mail. Valeurs possibles : Identiques à celles de headerCharset (voir ci-dessus) |
If the options parameter is omitted, the mail mode UTF8 configuration is used for header and body parts.
Exemple
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--