UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

108 lines 4.74 kB
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _SpoMailSendCommand_instances, _SpoMailSendCommand_initTelemetry, _SpoMailSendCommand_initOptions, _SpoMailSendCommand_initValidators; import request from '../../../../request.js'; import { validation } from '../../../../utils/validation.js'; import SpoCommand from '../../../base/SpoCommand.js'; import commands from '../../commands.js'; import outlookCommands from '../../../outlook/commands.js'; class SpoMailSendCommand extends SpoCommand { get name() { return commands.MAIL_SEND; } get description() { return 'Sends an e-mail from SharePoint'; } constructor() { super(); _SpoMailSendCommand_instances.add(this); __classPrivateFieldGet(this, _SpoMailSendCommand_instances, "m", _SpoMailSendCommand_initTelemetry).call(this); __classPrivateFieldGet(this, _SpoMailSendCommand_instances, "m", _SpoMailSendCommand_initOptions).call(this); __classPrivateFieldGet(this, _SpoMailSendCommand_instances, "m", _SpoMailSendCommand_initValidators).call(this); } async commandAction(logger, args) { await this.showDeprecationWarning(logger, commands.MAIL_SEND, outlookCommands.MAIL_SEND); const params = { properties: { __metadata: { "type": "SP.Utilities.EmailProperties" }, Body: args.options.body, Subject: args.options.subject, To: { results: args.options.to.replace(/\s+/g, '').split(',') } } }; if (args.options.from && args.options.from.length > 0) { params.properties.From = args.options.from; } if (args.options.cc && args.options.cc.length > 0) { params.properties.CC = { results: args.options.cc.replace(/\s+/g, '').split(',') }; } if (args.options.bcc && args.options.bcc.length > 0) { params.properties.BCC = { results: args.options.bcc.replace(/\s+/g, '').split(',') }; } if (args.options.additionalHeaders) { const h = JSON.parse(args.options.additionalHeaders); params.properties.AdditionalHeaders = { __metadata: { "type": "Collection(SP.KeyValue)" }, results: Object.keys(h).map(key => { return { __metadata: { type: 'SP.KeyValue' }, Key: key, Value: h[key], ValueType: 'Edm.String' }; }) }; } const requestOptions = { url: `${args.options.webUrl}/_api/SP.Utilities.Utility.SendEmail`, headers: { 'content-type': 'application/json;odata=verbose' }, responseType: 'json', data: params }; try { await request.post(requestOptions); } catch (err) { this.handleRejectedODataJsonPromise(err); } } } _SpoMailSendCommand_instances = new WeakSet(), _SpoMailSendCommand_initTelemetry = function _SpoMailSendCommand_initTelemetry() { this.telemetry.push((args) => { Object.assign(this.telemetryProperties, { from: typeof args.options.from !== 'undefined', cc: typeof args.options.cc !== 'undefined', bcc: typeof args.options.bcc !== 'undefined', additionalHeaders: typeof args.options.additionalHeaders !== 'undefined' }); }); }, _SpoMailSendCommand_initOptions = function _SpoMailSendCommand_initOptions() { this.options.unshift({ option: '-u, --webUrl <webUrl>' }, { option: '--to <to>' }, { option: '--subject <subject>' }, { option: '--body <body>' }, { option: '--from [from]' }, { option: '--cc [cc]' }, { option: '--bcc [bcc]' }, { option: '--additionalHeaders [additionalHeaders]' }); }, _SpoMailSendCommand_initValidators = function _SpoMailSendCommand_initValidators() { this.validators.push(async (args) => validation.isValidSharePointUrl(args.options.webUrl)); }; export default new SpoMailSendCommand(); //# sourceMappingURL=mail-send.js.map