1 | ;
|
2 | /**
|
3 | * This file is part of the @egodigital/egoose distribution.
|
4 | * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
|
5 | *
|
6 | * @egodigital/egoose is free software: you can redistribute it and/or modify
|
7 | * it under the terms of the GNU Lesser General Public License as
|
8 | * published by the Free Software Foundation, version 3.
|
9 | *
|
10 | * @egodigital/egoose is distributed in the hope that it will be useful, but
|
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | * Lesser General Public License for more details.
|
14 | *
|
15 | * You should have received a copy of the GNU Lesser General Public License
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 | */
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | const _ = require("lodash");
|
20 | const index_1 = require("../index");
|
21 | const ews = require('@egodigital/node-ews');
|
22 | /**
|
23 | * List of mail formats.
|
24 | */
|
25 | var MailFormat;
|
26 | (function (MailFormat) {
|
27 | /**
|
28 | * Plain text.
|
29 | */
|
30 | MailFormat[MailFormat["PlainText"] = 0] = "PlainText";
|
31 | /**
|
32 | * Rich text HTML
|
33 | */
|
34 | MailFormat[MailFormat["HTML"] = 1] = "HTML";
|
35 | })(MailFormat = exports.MailFormat || (exports.MailFormat = {}));
|
36 | /**
|
37 | * Sends an email.
|
38 | *
|
39 | * @param {SendMailOptions} opts Options.
|
40 | */
|
41 | async function sendMail(opts) {
|
42 | if (!opts) {
|
43 | opts = {};
|
44 | }
|
45 | const EWS_CONFIG = {
|
46 | username: process.env.EWS_USERNAME,
|
47 | password: process.env.EWS_PASSWORD,
|
48 | host: 'https://outlook.office.de',
|
49 | auth: 'basic'
|
50 | };
|
51 | let format = opts.format;
|
52 | if (_.isNil(format)) {
|
53 | format = MailFormat.PlainText;
|
54 | }
|
55 | let bodyType = 'Text';
|
56 | switch (format) {
|
57 | case MailFormat.HTML:
|
58 | bodyType = 'HTML';
|
59 | break;
|
60 | }
|
61 | const EWS_ARGS = {
|
62 | "attributes": {
|
63 | "MessageDisposition": "SendAndSaveCopy"
|
64 | },
|
65 | "SavedItemFolderId": {
|
66 | "DistinguishedFolderId": {
|
67 | "attributes": {
|
68 | "Id": "sentitems"
|
69 | }
|
70 | }
|
71 | },
|
72 | "Items": {
|
73 | "Message": {
|
74 | "ItemClass": "IPM.Note",
|
75 | "Subject": index_1.toStringSafe(opts.subject)
|
76 | .trim(),
|
77 | "Body": {
|
78 | "attributes": {
|
79 | "BodyType": bodyType
|
80 | },
|
81 | "$value": index_1.toStringSafe(opts.body),
|
82 | },
|
83 | "ToRecipients": {
|
84 | "Mailbox": {
|
85 | "EmailAddress": index_1.normalizeString(opts.to),
|
86 | }
|
87 | },
|
88 | "IsRead": "false",
|
89 | }
|
90 | }
|
91 | };
|
92 | await (new ews(EWS_CONFIG))
|
93 | .run('CreateItem', EWS_ARGS);
|
94 | }
|
95 | exports.sendMail = sendMail;
|
96 | //# sourceMappingURL=index.js.map |
\ | No newline at end of file |