Skip to content

informat.email Email Related Operations

Overview

Use the informat.email object to send emails

send

Send an email

javascript
informat.email.send(server, message);

Note

When the email address is incorrect or the server connection fails, the email will fail to send. After failure, an exception will be thrown.

ParameterTypeDescription
serverEmailServerEmail sending server
messageEmailMessageEmail content

Example

javascript
const server = {
    host: 'smtp.gmail.com',
    port: 465,
    ssl: true,
    auth: true,
    account: 'account@ainformat.com',
    password: 'password',
    protocol: 'smtp'
}
const textMessage = {
    recipients: [
        { address: 'to1@ainformat.com', 'personal': 'sky', type: 'TO' },
        { address: 'cc1@ainformat.com', 'personal': 'ginko', type: 'CC' },//CC
    ],
    subject: 'Email Subject',
    personal: 'Sender Nickname',
    text: 'Plain text email content',//Plain text content
}
const richMessage = {
    recipients: [
        { address: 'to1@ainformat.com', 'personal': 'sky', type: 'TO' },
        { address: 'cc1@ainformat.com', 'personal': 'ginko', type: 'CC' },//CC
    ],
    subject: 'Email Subject',
    personal: 'Sender Nickname',
    multiparts: [
        {
            type: 'text',
            content: 'Plain text content'
        },
        {
            type: 'content',
            contentType: "text/html;charset=utf-8",
            content: '<div style="color:red">Rich text content</div><img src="cid:image1"/>'
        },
        {
            type: 'attachment',
            contentId: '<image1>',
            disposition: 'inline',
            filename: 'image1.jpg',
            filepath: "logo.jpg"
        },//Image displayed in rich text
        {
            type: 'attachment',
            filename: 'excel.xlsx',
            filepath: "test.xlsx"
        },//Email attachment (local file)
        {
            type: 'attachment',
            filename: 'excel.xlsx',
            storageFilepath: "test.xlsx"
        }//Email attachment (shared storage file)
    ]
}
//
try {
    informat.email.send(server, textMessage);
    informat.email.send(server, richMessage);
} catch (e) {
    console.log('Send failed');
}

sendWithSystemServer

Send email using the system mailbox

javascript
informat.email.sendWithSystemServer(message);

Note

When the email address is incorrect or the server connection fails, the email will fail to send. After failure, an exception will be thrown. System mailbox configuration can be viewed here.

ParameterTypeDescription
messageEmailMessageEmail content

Example

js
const textMessage = {
    recipients: [
        { address: 'to1@ainformat.com', 'personal': 'sky', type: 'TO' },
        { address: 'cc1@ainformat.com', 'personal': 'ginko', type: 'CC' },//CC
    ],
    subject: 'Email Subject',
    personal: 'Sender Nickname',
    text: 'Plain text email content',//Plain text content
}
informat.email.sendWithSystemServer(textMessage);