Skip to content

Commit 4286cf7

Browse files
committed
review
1 parent 6d2dee9 commit 4286cf7

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ __BREAKING CHANGES:__
88
___
99
- IMPROVE: Optimize queries on classes with pointer permissions. [#7061](https://github.com/parse-community/parse-server/pull/7061). Thanks to [Pedro Diaz](https://github.com/pdiaz)
1010
- FIX: request.context for afterFind triggers. [#7078](https://github.com/parse-community/parse-server/pull/7078). Thanks to [dblythy](https://github.com/dblythy)
11-
- NEW: sendMail via Parse.Cloud.sendMail({...}). [#7089](https://github.com/parse-community/parse-server/pull/7089). Thanks to [dblythy](https://github.com/dblythy)
11+
- NEW: Added convenience method Parse.Cloud.sendMail(...) to send email via mail adapter in Cloud Code. [#7089](https://github.com/parse-community/parse-server/pull/7089). Thanks to [dblythy](https://github.com/dblythy)
1212

1313
### 4.5.0
1414
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0)

spec/CloudCode.spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3167,6 +3167,9 @@ describe('afterLogin hook', () => {
31673167
const query = new Parse.Query(TestObject);
31683168
await query.find({ context: { a: 'a' } });
31693169
});
3170+
});
3171+
3172+
describe('sendMail', () => {
31703173
it('can send email via Parse.Cloud', async done => {
31713174
const emailAdapter = {
31723175
sendMail: mailData => {
@@ -3181,12 +3184,15 @@ describe('afterLogin hook', () => {
31813184
const mailData = { to: 'test' };
31823185
await Parse.Cloud.sendMail(mailData);
31833186
});
3187+
31843188
it('cannot send email without adapter', async () => {
31853189
try {
31863190
await Parse.Cloud.sendMail({});
31873191
fail('Should have failed to send emails.');
31883192
} catch (e) {
3189-
expect(e).toBe('You cannot send mail without an email adapter');
3193+
expect(e).toBe(
3194+
'Failed to send email because no mail adapter is configured for Parse Server.'
3195+
);
31903196
}
31913197
});
31923198
});

src/cloud-code/Parse.Cloud.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,25 +530,29 @@ ParseCloud.beforeConnect = function (handler, validationHandler) {
530530
};
531531

532532
/**
533-
* Sends email through your mail adapter
533+
* Sends an email through the Parse Server mail adapter.
534534
*
535535
* **Available in Cloud Code only.**
536-
*
537-
* **Requires a mail adapter to be set**
536+
* **Requires a mail adapter to be configured for Parse Server.**
538537
*
539538
* ```
540-
* Parse.Cloud.sendMail(data);
539+
* Parse.Cloud.sendMail({
540+
* from: 'Example <test@example.com>',
541+
542+
* subject: 'Test email.',
543+
* text: 'This email is a test'
544+
* });
541545
*```
542546
*
543547
* @method sendMail
544548
* @name Parse.Cloud.sendMail
545-
* @param {Any} data The object of the mail data that you'd like to send
549+
* @param {Object} data The object of the mail data to send
546550
*/
547551
ParseCloud.sendMail = function (data) {
548552
const config = Config.get(Parse.applicationId) || {};
549553
const emailAdapter = config.userController.adapter;
550554
if (!emailAdapter) {
551-
throw 'You cannot send mail without an email adapter';
555+
throw 'Failed to send email because no mail adapter is configured for Parse Server.';
552556
}
553557
return emailAdapter.sendMail(data);
554558
};

0 commit comments

Comments
 (0)