|
1 | 1 | import { Parse } from 'parse/node'; |
2 | 2 | import * as triggers from '../triggers'; |
| 3 | +const Config = require('../Config'); |
3 | 4 |
|
4 | 5 | function isParseObjectConstructor(object) { |
5 | 6 | return typeof object === 'function' && Object.prototype.hasOwnProperty.call(object, 'className'); |
@@ -528,6 +529,37 @@ ParseCloud.beforeConnect = function (handler, validationHandler) { |
528 | 529 | ); |
529 | 530 | }; |
530 | 531 |
|
| 532 | +/** |
| 533 | + * Sends an email through the Parse Server mail adapter. |
| 534 | + * |
| 535 | + * **Available in Cloud Code only.** |
| 536 | + * **Requires a mail adapter to be configured for Parse Server.** |
| 537 | + * |
| 538 | + * ``` |
| 539 | + * Parse.Cloud.sendEmail({ |
| 540 | + * from: 'Example <test@example.com>', |
| 541 | + * to: 'contact@example.com', |
| 542 | + * subject: 'Test email', |
| 543 | + * text: 'This email is a test.' |
| 544 | + * }); |
| 545 | + *``` |
| 546 | + * |
| 547 | + * @method sendEmail |
| 548 | + * @name Parse.Cloud.sendEmail |
| 549 | + * @param {Object} data The object of the mail data to send. |
| 550 | + */ |
| 551 | +ParseCloud.sendEmail = function (data) { |
| 552 | + const config = Config.get(Parse.applicationId); |
| 553 | + const emailAdapter = config.userController.adapter; |
| 554 | + if (!emailAdapter) { |
| 555 | + config.loggerController.error( |
| 556 | + 'Failed to send email because no mail adapter is configured for Parse Server.' |
| 557 | + ); |
| 558 | + return; |
| 559 | + } |
| 560 | + return emailAdapter.sendMail(data); |
| 561 | +}; |
| 562 | + |
531 | 563 | /** |
532 | 564 | * Registers a before live query subscription function. |
533 | 565 | * |
|
0 commit comments