UNPKG

@egodigital/egoose

Version:

Helper classes and functions for Node.js 10 or later.

96 lines 2.93 kB
"use strict"; /** * This file is part of the @egodigital/egoose distribution. * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/) * * @egodigital/egoose is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, version 3. * * @egodigital/egoose is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ Object.defineProperty(exports, "__esModule", { value: true }); const _ = require("lodash"); const index_1 = require("../index"); const ews = require('@egodigital/node-ews'); /** * List of mail formats. */ var MailFormat; (function (MailFormat) { /** * Plain text. */ MailFormat[MailFormat["PlainText"] = 0] = "PlainText"; /** * Rich text HTML */ MailFormat[MailFormat["HTML"] = 1] = "HTML"; })(MailFormat = exports.MailFormat || (exports.MailFormat = {})); /** * Sends an email. * * @param {SendMailOptions} opts Options. */ async function sendMail(opts) { if (!opts) { opts = {}; } const EWS_CONFIG = { username: process.env.EWS_USERNAME, password: process.env.EWS_PASSWORD, host: process.env.EWS_HOST || 'https://outlook.office.de', auth: 'basic' }; let format = opts.format; if (_.isNil(format)) { format = MailFormat.PlainText; } let bodyType = 'Text'; switch (format) { case MailFormat.HTML: bodyType = 'HTML'; break; } const EWS_ARGS = { "attributes": { "MessageDisposition": "SendAndSaveCopy" }, "SavedItemFolderId": { "DistinguishedFolderId": { "attributes": { "Id": "sentitems" } } }, "Items": { "Message": { "ItemClass": "IPM.Note", "Subject": index_1.toStringSafe(opts.subject) .trim(), "Body": { "attributes": { "BodyType": bodyType }, "$value": index_1.toStringSafe(opts.body), }, "ToRecipients": { "Mailbox": { "EmailAddress": index_1.normalizeString(opts.to), } }, "IsRead": "false", } } }; await (new ews(EWS_CONFIG)) .run('CreateItem', EWS_ARGS); } exports.sendMail = sendMail; //# sourceMappingURL=index.js.map