infinity.mail¶
Provides functionality for creating, as well as reading or writing standard conform email data from or to files and streams.
Module: infinity.mail
Example:
infinity.loadModule('infinity.mail');
let myMail = new infinity.mail();
myMail.replyTo = 'support@site.com';
myMail.from = 'mailer@site.com';
myMail.sender = 'sender@site.com';
myMail.returnPath = 'mailFailed@site.com';
myMail.charset = 'utf-8';
myMail.organization = 'Corporation Institution';
myMail.userAgent = 'INFINITY.JS';
myMail.recipients = ['recipient@site.com', 'secondRecipient@site.com'];
myMail.cc = ['copyRecipient@site.com'];
myMail.bcc = ['blindCopyRecipient@site.com'];
myMail.envelopeTo = 'recipient@site.com';
myMail.subject = 'Mailsubject';
myMail.contents = [{
contentType: 'text/html',
contentTransferEncoding: infinity.mail.transferEncoding.quotedPrintable,
charset: 'utf-8',
text: 'Hello, this is my mailtext. And here is a picture: <img src="cid:att01.bmp">',
items: []
}];
myMail.attachments = [{
name: 'image.bmp',
size: 1254,
contentType: 'image/bmp',
contentTransferEncoding: infinity.mail.transferEncoding.base64,
contentId: 'att01.bmp',
contentDisposition: 'inline',
storedFilePath: infinity.current.root + '../image.bmp'
}]
myMail.saveToFile(infinity.current.root + '../mail.eml');
Resulting mail.eml:
Return-Path: <mailFailed@site.com>
From: <mailer@site.com>
Sender: <sender@site.com>
Reply-To: <support@site.com>
To: <recipient@site.com>,
<secondRecipient@site.com>
CC: <copyRecipient@site.com>
Organization: Corporation Institution
X-Mailer: INFINITY.JS
X-Priority: 3 (Normal)
Subject: Mailsubject [T-5LHR1OS2MM-69]
Date: Thu, 8 Apr 2021 16:24:33 +0000
Content-Transfer-Encoding: 7bit
Content-Type: multipart/related;
boundary="_NextPart_f40c92e644d38073e5521df63cb73a57"
MIME-Version: 1.0
This is a multi-part message in MIME format
--_NextPart_f40c92e644d38073e5521df63cb73a57
Content-Type: text/html;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Hello, this is my mailtext. And here is a picture: <img src=3D"cid:att01.bm=
p">
--_NextPart_f40c92e644d38073e5521df63cb73a57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jCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNTc8h
CvDNh7UbCvDNTc8hCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNydwh
CvDNCvDN8cQbCvDNCvDNydwhCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDN1fghX+sh
CvDNCvDNCvDNldMbCvDNCvDNCvDNX+sh1fghCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNcBkjCvDN
CvDNCvDNCvDNCvDN/OEbCvDNCvDNCvDNCvDNCvDNcBkjCvDNCvDNCvDNCvDNCvDNCvDN4DkjCvDN
CvDNCvDNCvDNCvDNCvDNo+8bCvDNCvDNCvDNCvDNCvDNCvDN4DkjCvDNCvDNCvDN62gjf1MjCvDN
CvDNCvDNCvDNCvDNCvDNCvDNHfwbCvDNCvDNCvDNCvDNCvDNCvDNCvDNf1Mj62gjjnwjCvDNCvDN
CvDNCvDNCvDNCvDNCvDNCvDNCvDNsCUdCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDN
CvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNOEMdCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDN
CvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNvFkdCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDNCvDN
--_NextPart_f40c92e644d38073e5521df63cb73a57--
Example for working with received emails:
infinity.loadModule('infinity.mail');
infinity.loadModule('infinity.fileSystem');
let myMail = new infinity.mail();
myMail.loadFromFile('C:/tmp/email.eml');
infinity.file.writeString('c:/tmp/mailContent.txt', myMail.getTextContent());
mail¶
The class for operations with email files.
Properties:
- attachments
- bcc
- boundary
- cc
- charset
- contentTransferEncoding
- contentType
- contents
- date
- deliveryNotification
- envelopeTo
- extendedHeaders
- from
- organization
- priority
- recipients
- replyTo
- returnPath
- sender
- subject
- userAgent
- inReplyTo
- messageId
- multipartType
- receivedFrom
- size
Methods:
Example:
infinity.loadModule('infinity.mail');
let myMail = new infinity.mail();
Properties
attachments¶
Type: infinity.mail.attachmentArray
Gets or sets the attachments for the current email. The data must be passed and will be retreived inside an infinity.mail.stringArray
. See the example on top of this page for more information.
bcc¶
Type: infinity.mail.stringArray
Gets or sets the blind carbon copy recipients for the current email. The data must be passed and will be retreived inside an infinity.mail.stringArray
. See the example on top of this page for more information.
boundary¶
Type: string
Gets or sets the boundary for the current email.
cc¶
Type: infinity.mail.stringArray
Gets or sets the CC
header for the current email. The data must be passed and will be retreived inside an infinity.mail.stringArray
. See the example on top of this page for more information.
charset¶
Type: string
Gets or sets the character encoding for the current email.
contentTransferEncoding¶
Type: infinity.mail.transferEncoding
Gets or sets the Content-Transfer-Encoding
header for the current email according to the infinity.mail.transferEncoding
enum.
contentType¶
Type: string
Gets or sets the MIME Content-Type
header for the current email.
contents¶
Type: infinity.mail.contentArray
Gets or sets the contents for the current email. The data must be passed and will be retreived inside an infinity.mail.stringArray
. See the example on top of this page for more information.
date¶
Type: number
Gets or sets the Date
header for the current email.
deliveryNotification¶
Type: string
Gets or sets the delivery notification flag for the current email.
envelopeTo¶
Type: string
Gets or sets the X-Envelope-To
header for the current email.
extendedHeaders¶
Type: infinity.mail.headerArray
Allows for additional headers to be added.
from¶
Type: string
Gets or sets the From
header for the current email.
organization¶
Type: string
Gets or sets the Organization
header for the current email.
priority¶
Type: infinity.mail.priority
Gets or sets the X-Priority
header for the current email.
recipients¶
Type: infinity.mail.stringArray
Gets or sets the To
header for the current email. The data must be passed inside an infinity.mail.stringArray
. See the example on top of this page for more information.
replyTo¶
Type: string
Gets or sets the Reply-To
header for the current email.
returnPath¶
Type: string
Gets or sets the Return-Path
header for the current email.
sender¶
Type: string
Gets or sets the Sender
header for the current email.
subject¶
Type: string
Gets or sets the subject for the current email.
userAgent¶
Type: string
Gets or sets the X-Mailer
header for the current email.
inReplyTo¶
Type: string
Gets the data out of the In-Reply-To
header of the current email.
messageId¶
Type: string
Gets the data out of the Message-ID
header of the current email.
multipartType¶
Type: infinity.mail.multipartType
Gets the data out of the Message-ID
header of the current email according to the infinity.mail.multipartType
enum.
receivedFrom¶
Type: infinity.mail.stringArray
Gets the IPs of the servers from which the email has been received out of the Received
header of the current email.
size¶
Type: number
Gets the size of the current email.
Methods
constructor()¶
Lets you create an INFINITY.JS mail object instance.
Signature:
constructor( parseAttachment?: boolean)
Parameters:
- parseAttachment:
boolean
, optionalWhether to include attachments when loading mail from a file.
Example:
infinity.loadModule('infinity.mail');
let myMail = new infinity.mail();
clear()¶
Clears all data from the mail object instance.
Signature:
clear(): void
Example:
myMail.clear();
free()¶
Frees the memory previously occupied by the mail object instance instance.
Signature:
free(): void
Example:
myMail.free();
getBestContent()¶
Returns the most appropriate HTML or text content of the current mail.
Signature:
getBestContent( replaceCID: boolean ): string
Parameters:
- replaceCID:
boolean
Specifies whether image data should be put inline in place of the previous
cid:
entries.
Return type: string
Example:
myMail.getBestContent(true);
getHtmlContent()¶
Returns extracted html content from the email inside the mail object instance.
Signature:
getHtmlContent( replaceCID: boolean ): string
Parameters:
- replaceCID:
boolean
Specifies whether imaga data should be put inline in place of the previous
cid:
entries.
Return type: string
Example:
myMail.getHtmlContent(true);
getTextContent()¶
Returns extracted text content from the email inside the mail object instance.
Signature:
getTextContent(): string
Return type: string
Example:
let textContent = myMail.getTextContent();
loadFromFile()¶
Loads data from the specified email-file into the mail object instance.
Signature:
loadFromFile( fileName: string ): void
Parameters:
- fileName:
string
Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file which has to be loaded.
Example:
myMail.loadFromFile(infinity.current.root + '../mail.eml');
loadFromStream()¶
Loads data from the given stream into the mail object instance.
Signature:
loadFromStream( stream: infinity.stream ): void
Parameters:
- stream:
infinity.stream
Stream object to receive email data from. See infinity.stream.
Example:
myMail.loadFromStream(stream);
saveToFile()¶
Saves standard conform email data from the mail object instance to a file.
Signature:
saveToFile( fileName: string ): void
Parameters:
- fileName:
string
Filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the file to save the data to.
Example:
myMail.saveToFile(fileName);
saveToStream()¶
Saves standard conform email data from the mail object instance to the given stream.
Signature:
saveToStream( stream: infinity.stream ): void
Parameters:
- stream:
infinity.stream
Stream object to write email data to. See infinity.stream.
Example:
myMail.saveToStream(stream);
attachmentArray¶
Extends: Array<{name: string, size: number, contentType: string, contentTransferEncoding: infinity.mail.transferEncoding, contentId: string, contentDisposition: string, storedFilePath: string}>
An array containing objects with attachment data inside its properties.
Properties:¶
-
name¶
Type:
string
. The name of the attachment for the corresponding parameter of theContent-Type
attachment header. -
size¶
Type:
number
. The size of the attachment in bytes. -
contentTransferEncoding¶
Type:
infinity.mail.transferEncoding
. The transfer encoding for the attachment. -
contentId¶
Type:
string
. The content id ("cid") for e.g. inline insertion of the attachment into the email content. -
contentDisposition¶
Type:
string
. The entry for theContent-Disposition
header. -
storedFilePath¶
Type:
string
. The filename, relative path (location relative to the folder with the used INFINITY.JS executable file) or absolute path to the attachment file.
contentArray¶
Extends: Array<{contentType: string, contentTransferEncoding: infinity.mail.transferEncoding, charset: string, text: string, items: infinity.mail.contentArray}>
Properties:¶
-
contentType¶
Type:
string
. The MIME content type for the corresponding email header. -
contentTransferEncoding¶
Type:
infinity.mail.transferEncoding
. The transfer encoding for the email body content. -
charset¶
Type:
string
. The character encoding identifier for the email body content. -
text¶
Type:
string
. The email body content. -
items¶
Type:
infinity.mail.contentArray
.
headerArray¶
Extends: Array<{name: string, value: string}>
An array containing objects with data inside its properties.
Properties:¶
stringArray¶
Extends: Array<string>
An array of strings.
infinity.mail.multipartType¶
Values:
-
none:
0
Stands for.
-
alternative:
1
Stands for the
multipart/related
Content-Type
header declaration. -
other:
2
Stands for the
multipart/other
Content-Type
header declaration.
Example:
infinity.loadModule('infinity.mail');
let multipartType = infinity.mail.multipartType.none;
infinity.mail.priority¶
Values:
-
lowest:
0
Stands for the
5 (Lowest)
X-Priority
email header declaration. -
lower:
1
Stands for the
4 (Lower)
X-Priority
email header declaration. -
normal:
2
Stands for the
3 (Normal)
X-Priority
email header declaration. -
higher:
3
Stands for the
2 (Higher)
X-Priority
email header declaration. -
highest:
4
Stands for the
1 (Highest)
X-Priority
email header declaration.
Example:
infinity.loadModule('infinity.mail');
let priority = infinity.mail.priority.lowest;
infinity.mail.transferEncoding¶
Values:
-
bit7:
0
Stands for the
7bit
Content-Transfer-Encoding
email header declaration. -
bit8:
1
Stands for the
8bit
Content-Transfer-Encoding
email header declaration. -
binary:
2
Stands for the
binary
Content-Transfer-Encoding
email header declaration. -
quotedPrintable:
3
Stands for the
quoted-printable
Content-Transfer-Encoding
email header declaration. -
base64:
4
Stands for the
base64
Content-Transfer-Encoding
email header declaration.
Example:
infinity.loadModule('infinity.mail');
let transferEncoding = infinity.mail.transferEncoding.bit7;