-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send email via Parse.Cloud.sendEmail (#7096)
* initial * more tests * Update CHANGELOG.md * review * log on error * change logger to error * rename * Update Parse.Cloud.js
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { Parse } from 'parse/node'; | ||
import * as triggers from '../triggers'; | ||
const Config = require('../Config'); | ||
|
||
function isParseObjectConstructor(object) { | ||
return typeof object === 'function' && Object.prototype.hasOwnProperty.call(object, 'className'); | ||
|
@@ -528,6 +529,37 @@ ParseCloud.beforeConnect = function (handler, validationHandler) { | |
); | ||
}; | ||
|
||
/** | ||
* Sends an email through the Parse Server mail adapter. | ||
* | ||
* **Available in Cloud Code only.** | ||
* **Requires a mail adapter to be configured for Parse Server.** | ||
* | ||
* ``` | ||
* Parse.Cloud.sendEmail({ | ||
* from: 'Example <[email protected]>', | ||
* to: '[email protected]', | ||
* subject: 'Test email', | ||
* text: 'This email is a test.' | ||
* }); | ||
*``` | ||
* | ||
* @method sendEmail | ||
* @name Parse.Cloud.sendEmail | ||
* @param {Object} data The object of the mail data to send. | ||
*/ | ||
ParseCloud.sendEmail = function (data) { | ||
const config = Config.get(Parse.applicationId); | ||
const emailAdapter = config.userController.adapter; | ||
if (!emailAdapter) { | ||
config.loggerController.error( | ||
'Failed to send email because no mail adapter is configured for Parse Server.' | ||
); | ||
return; | ||
} | ||
return emailAdapter.sendMail(data); | ||
}; | ||
|
||
/** | ||
* Registers a before live query subscription function. | ||
* | ||
|