Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send email via Parse.Cloud.sendEmail #7096

Merged
merged 8 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ __BREAKING CHANGES:__
___
- 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)
- FIX: request.context for afterFind triggers. [#7078](https://github.com/parse-community/parse-server/pull/7078). Thanks to [dblythy](https://github.com/dblythy)
- NEW: sendMail via Parse.Cloud.sendMail({...}). [#7089](https://github.com/parse-community/parse-server/pull/7089). Thanks to [dblythy](https://github.com/dblythy)
dblythy marked this conversation as resolved.
Show resolved Hide resolved

### 4.5.0
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0)
Expand Down
22 changes: 22 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3167,4 +3167,26 @@ describe('afterLogin hook', () => {
const query = new Parse.Query(TestObject);
await query.find({ context: { a: 'a' } });
});
it('can send email via Parse.Cloud', async done => {
dblythy marked this conversation as resolved.
Show resolved Hide resolved
const emailAdapter = {
sendMail: mailData => {
expect(mailData).toBeDefined();
expect(mailData.to).toBe('test');
done();
},
};
await reconfigureServer({
emailAdapter: emailAdapter,
});
const mailData = { to: 'test' };
await Parse.Cloud.sendMail(mailData);
});
it('cannot send email without adapter', async () => {
try {
await Parse.Cloud.sendMail({});
fail('Should have failed to send emails.');
} catch (e) {
expect(e).toBe('You cannot send mail without an email adapter');
}
});
});
25 changes: 25 additions & 0 deletions src/cloud-code/Parse.Cloud.js
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');
Expand Down Expand Up @@ -528,6 +529,30 @@ ParseCloud.beforeConnect = function (handler, validationHandler) {
);
};

/**
* Sends email through your mail adapter
dblythy marked this conversation as resolved.
Show resolved Hide resolved
*
* **Available in Cloud Code only.**
*
dblythy marked this conversation as resolved.
Show resolved Hide resolved
* **Requires a mail adapter to be set**
dblythy marked this conversation as resolved.
Show resolved Hide resolved
*
* ```
* Parse.Cloud.sendMail(data);
dblythy marked this conversation as resolved.
Show resolved Hide resolved
*```
*
* @method sendMail
dblythy marked this conversation as resolved.
Show resolved Hide resolved
* @name Parse.Cloud.sendMail
* @param {Any} data The object of the mail data that you'd like to send
dblythy marked this conversation as resolved.
Show resolved Hide resolved
*/
ParseCloud.sendMail = function (data) {
dblythy marked this conversation as resolved.
Show resolved Hide resolved
const config = Config.get(Parse.applicationId) || {};
const emailAdapter = config.userController.adapter;
dblythy marked this conversation as resolved.
Show resolved Hide resolved
if (!emailAdapter) {
throw 'You cannot send mail without an email adapter';
dblythy marked this conversation as resolved.
Show resolved Hide resolved
}
return emailAdapter.sendMail(data);
};

/**
* Registers a before live query subscription function.
*
Expand Down